Welcome, Guest. Please login or register.
Did you miss your activation email?
September 20, 2014, 09:57:00 AM

Login with username, password and session length

Recent

Members
Stats
  • Total Posts: 173968
  • Total Topics: 19849
  • Online Today: 98
  • Online Ever: 278
  • (October 31, 2012, 08:52:18 AM)
Users Online
Users: 3
Guests: 31
Total: 34
Please read the Posting Guidelines

Author Topic: [Block] Articles, simple index  (Read 3684 times)

0 Members and 1 Guest are viewing this topic.

Online Freddy

  • Moderator
  • *
  • Posts: 1570
    • AiDreams
[Block] Articles, simple index
« on: September 19, 2010, 09:03:57 AM »
Name of Snippet: Articles, Simple Index
SMF/TP versions tested:
SMF1/TinyPortal v1.0.5 beta 1
SMF1/TinyPortal 1.0 beta 5-2
SMF 2.0 RC3/TinyPortal 1.0 beta 5.2
Block Type: php block or php article
Author: Freddy
Link to Discussion: http://www.tinyportal.net/index.php?topic=31110.0
Other Requirements: none
Description:

This will simply list the articles in the categories by date.  There's no pagination or anything so if you have hundreds of articles then you'd probably want to try something else - I believe there are other blocks that do this, so try searching.

I use this in a PHP article and simply link to the page from a menu.

You could change the SQL 'ORDER BY date DESC' to 'ORDER BY subject' and make it alphabetical if you want that instead.
« Last Edit: October 27, 2011, 09:45:32 AM by Freddy »

Online Freddy

  • Moderator
  • *
  • Posts: 1570
    • AiDreams
Re: [Block] Articles, simple index
« Reply #1 on: September 19, 2010, 09:05:37 AM »
Here's the code for SMF 1, just customise the settings and text as you wish.

Code: [Select]
// Configuration

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

// The heading area.

echo '
<div style="text-align: center; border: 1px solid #242526; ">
<h3>Articles Index</h3>
<p>A short introduction can go in here...maybe an image too.</p>
</div>
<br />';

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

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

$request = db_query("SELECT id, date, subject, views, shortname FROM {$db_prefix}tp_articles WHERE category IN ($cats) AND off = 0 ORDER BY date DESC", __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);

Online Freddy

  • Moderator
  • *
  • Posts: 1570
    • AiDreams
Re: [Block] Articles, simple index
« Reply #2 on: September 19, 2010, 09:06:06 AM »
Here's the code for SMF 2, just customise the settings and text as you wish.

Code: [Select]
// Configuration

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

// The heading area.

echo '
<div style="text-align: center; border: 1px solid #242526; ">
<h3>Articles Index</h3>
<p>A short introduction can go in here...maybe an image too.</p>
</div>
<br />';

// 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", __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);

Online Freddy

  • Moderator
  • *
  • Posts: 1570
    • AiDreams
Re: [Block] Articles, simple index
« Reply #3 on: October 27, 2011, 09:45:04 AM »
Thanks to IcBin and Lurkalot here is the code for SMF2 & TP1

No demo but image is attached below...


Code: [Select]
// Configuration

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

// The heading area.

echo '
<div style="text-align: center; border: 1px solid #242526; ">   
   <h3>Articles Index</h3>
   <p>This is a list of articles, submitted by our members.</p>
</div>
<br />';

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

$request = $smcFunc['db_query']('', '
SELECT id, date, subject, views, shortname
FROM {db_prefix}tp_articles
WHERE category IN ({array_int:cats})
AND off = 0
ORDER BY date DESC',
array('cats' => $categories)
);

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

while ($row = $smcFunc['db_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>';

$smcFunc['db_free_result']($request);