WebsiteBaker Support (2.8.x) > Droplets & Snippets
Front Page News
pszilard:
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.
albatros:
Hi,
yes it is possible. Have a look on "any news" http://addons.WebsiteBaker.org/pages/modules/code-snippets.php
hth
Uwe
stinkywinky:
Another easy option is to put the next code inside your template:
--- Code: ---
<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 -->
--- End code ---
pszilard:
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.
stinkywinky:
Just put the code inside your template!
Navigation
[0] Message Index
[#] Next page
Go to full version