I have a dedicated News Page, which works fine.
I would like to be able to pickup the latest "x" number news items to show on my Home Page. Is this easily doable? I tried searching the forums but could find an answer, but if this is already discussed somewhere, please give me a pointer. Ta.
Hi,
yes it is possible. Have a look on "any news" http://addons.WebsiteBaker.org/pages/modules/code-snippets.php (http://addons.websitebaker.org/pages/modules/code-snippets.php)
hth
Uwe
Another easy option is to put the next code inside your template:
<ul>
<!-- NEWS READER -->
<?php
$group = 3; // Specify the Group(id) you want to read the news from
global $database;
$query = "SELECT *, DATE_FORMAT(FROM_UNIXTIME(posted_when), '%d/%m/%Y') AS datum_nl
FROM ".TABLE_PREFIX."mod_news_posts
WHERE group_id = $group
ORDER BY post_id
DESC LIMIT 0,3;";
// This limits the results to max 3, so if you want it to be 10, make it LIMIT 0, 10.
// The first number defines the starting point, and the second the max/end of the results
$content = mysql_query($query) or die (mysql_error() .'<BR>'. $query);
while ($data = mysql_fetch_array($content))
{
$id = $data[post_id];
$link = $data[link];
$query_comments = $database->query("SELECT title,comment,commented_when,commented_by FROM ".TABLE_PREFIX."mod_news_comments WHERE post_id = '".$id."'");
$comments_count=$query_comments->numRows();
?>
<li><? echo $data[datum_nl]; ?>-<a href="<?php echo WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;?>"><?php echo $data[title]; ?></a>
<br /><a class="nieuws" href="<?php echo WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;?>">lees het volledige bericht</a>
</li>
<?php
}
?>
<!-- END NEWS READER -->
Stinkywinky, how do I use this code? I tried inserting it into a Code section, but it wouldn't save. I also tried insert it into a WYSYWIG as Source and that didn't work either.
Just put the code inside your template!
Be aware that if you put this into your template that is will appear on every page and not just your front page...unless you use logic that only includes it if $pageid =0 (or whatever your front page is). I would prefer using Any News snippet (as albatros mentioned to you) and including it into a section on whatever page I want it to include it.
You could also use two templates, one with the code for the frontpage, an one without the code for pages without news.
Hans
I got it working by creating a Code Section with "display_news_items(4,20,150,0);" inside it.
Thanks for the pointers.