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,973
  • Latest: NonStop
Stats
  • Total Posts: 196,242
  • Total Topics: 21,353
  • Online today: 488
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 259
  • Total: 259

[Block] Simple ordered article list from one category

Started by freddy888, July 26, 2009, 08:25:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Freddy

As requested here is a simple piece of code you can put into a PHP block that will list in date or alphabetical order the articles in a certain category.  This is useful if the built in article list isn't functioning the way you want just yet.

Simply find your category by going into the admin control panel.  Go to TinyPortal->Articles and Categories.  Then look at the list of categories and click on the category you want to use.  Then look in the address bar and you will see something like :

http://localhost/forum1/index.php?action=tpadmin;sa=articles;artcat=3

The 3 or whatever yours is, equals the category id which you need to use in the code here:

global $scripturl, $db_prefix;

// Set your category id here...
$category = 3;

$request = db_query("
SELECT subject, id
FROM {$db_prefix}tp_articles
WHERE category
LIKE '$category'
ORDER BY date DESC", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
    echo '<span><strong><a href="' , $scripturl, '?page=' , $row['id'] , '">' , $row['subject'] , '</a></strong></span><br />';
}

mysql_free_result($request);


Just in case you have about fifty articles and only want to show the top five newest say, then all you need to do is :

Change this line :
ORDER BY date DESC", __FILE__, __LINE__);

To this :
ORDER BY date DESC LIMIT 5", __FILE__, __LINE__);

You get the idea...


If you want to order articles alphabetically instead then that's easy too:

Just change :
ORDER BY date DESC", __FILE__, __LINE__);

To this (you can add a limit too of course like above) :
ORDER BY subject ASC", __FILE__, __LINE__);


And maybe if you want to use it in a left block you will need smaller text so...

Change the <span> to <span class="smalltext">

Happy coding  :)


Freddy


vortodox

Great block, just what I needed!
Thanks a lot, all works perfectly!


Ragnor1234

This is a great block, thank you. I have a question about the code.  You know how the user or menu block has a small light yellow circle before every item in the block.  Is it possible to do the same thing in this code for the articles?


IchBin

Change this code:

while ($row = mysql_fetch_assoc($request))
{
     echo '<span><strong><a href="' , $scripturl, '?page=' , $row['id'] , '">' , $row['subject'] , '</a></strong></span><br />';
}


With this code:
echo '<ul>';
while ($row = mysql_fetch_assoc($request))
{
     echo '<li><strong><a href="' , $scripturl, '?page=' , $row['id'] , '">' , $row['subject'] , '</a></strong></li>';
}
echo '</ul>';

ragnor12345

Hey IchBin, sorry it took awhile to post my results, apparently my comcast isp won't execpt emails from the site.  So i created a new username with a different email address. 

your code worked great  :)  but it left some space at the left, bottom, and top side of the block before the bullets or any articles start.  It looks kind of werid becuase the other blocks don't show those spaces.  Is their a way to modify the code so the dots left allign and start at the top like the other blocks? 


IchBin

Would be nice if you'd post a link so I can see it.

ragnor12345

#9
ops, sorry ich.  My test site, this thing is still a very long work in progress.

"link removed"


This website is proudly hosted on Crocweb Cloud Website Hosting.