TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 348
  • Total: 348

[Discussion] Simple Article Index

Started by freddy888, October 08, 2009, 02:53:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Freddy

It's not too tricky if you know a little SQL.  Assuming you are on SMF 2 try this out.

As always let me know how you get on :)


// Block code to display x number of articles ordered by date and offset to ignore first x articles.
// SMF 2
// Freddy

// Configuration

// Specify your categories, comma separated if more than one category.
$categories = array(1,2,3,4,5);

// Limit the number of articles shown.
$limit = 5;

// Set the offset - in other words ignore the first x articles
$offset = 2;

// End Config


// Now for the code...
global $scripturl, $db_prefix;

$cats = implode(', ', $categories);

$request = tpdb_query("SELECT id, date, subject, views, shortname FROM {$db_prefix}tp_articles WHERE category IN ($cats) ORDER BY date DESC LIMIT $limit OFFSET $offset", __FILE__, __LINE__);

echo '
<table class="tborder" width="100%">
<tr class="titlebg">
<td>Subject</td>
<td>Date</td>
<td align="center">Views</td>
</tr>';

while ($row = mysql_fetch_assoc($request))
{
if ($row['shortname'])
{
$pageid = $row['shortname'];
}
else
{
$pageid = $row['id'];
}

echo '
<tr class="windowbg">
<td style="padding: 3px 0px 3px 10px"><strong><a href="' , $scripturl, '?page=' , $pageid , '">' , $row['subject'] , '</a></strong></td>
<td style="padding: 3px 0px 3px 10px">' , date('jS, F Y', $row['date']) , '</td>
<td align="center" style="padding: 3px 0px 3px 15px">' , $row['views'] , '</td>
</tr>
';
}

echo '
</table>';

mysql_free_result($request);

ZarPrime

Freddy,

Nice. O0 That's why you are a coder and I'm just support. :D

ZarPrime

Freddy

there's no 'just' about it ZP, you make a fine job of support :)

SN

Freddy, you never cease to amaze me... it's perfect.

Thanks Mate!

Freddy

No problem my friend, happy to help :)

Mick


Freddy


saks

it show titles of 5 last articles for selected categories:
// Configuration

// Specify your categories, comma separated if more than one category.
$categories = array(456);

// The heading area.

// Now for the code...
global $scripturl, $db_prefix;

$cats = implode(', ', $categories);

$request = tpdb_query("SELECT id, date, subject, views, shortname FROM {$db_prefix}tp_articles WHERE category IN ($cats) AND off = 0 ORDER BY date DESC LIMIT 0, 5", __FILE__, __LINE__);

echo '
<table  width="100%">';
$i = 0;
while ($row = mysql_fetch_assoc($request))
{

if ($row['shortname'])
{
$pageid = $row['shortname'];
}
else
{
$pageid = $row['id'];
}

echo '
<tr class="smalltext">
<td style="padding: 3px 0px 3px 8px"><li><a href="http://www.paraplanoff.net/' , $scripturl, '?page=' , $pageid , '">' , $row['subject'] , '</a></li></td>
</tr>
';
    if ($i == 4) {break;}
    $i = $i+1;
}

echo '
</table>';

mysql_free_result($request);

ZarPrime

saks,

I'll wait for Freddy to respond because I don't really understand what your question is.  However, it does look like you are missing some code in there and your category array is wrong because there should be a comma between each of the categories.

ZarPrime

Freddy

Sorry no idea what the question is either.  Please give us more details.

This website is proudly hosted on Crocweb Cloud Website Hosting.