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 :)
Great job Freddy!
Thanks again
Welcome ;D
Great block, just what I needed!
Thanks a lot, all works perfectly!
Nice one ;D
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?
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>';
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?
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi58.photobucket.com%2Falbums%2Fg242%2FJogfrantic%2Fnewsexample.jpg&hash=b677cfed5ff4814270cd17658ec5d16acb7896e8)
Would be nice if you'd post a link so I can see it.
ops, sorry ich. My test site, this thing is still a very long work in progress.
"link removed"
Thank you. I forgot that a unordered list "<ul>" has some default padding and margins. Change the first <ul> to this:
<ul style="margin: 0pt; padding: 0pt 15px;">
You can play with those numbers if you want a little more padding or not.
And that worked :). Thank you ich, i really appreciate it.