WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: pszilard on December 12, 2007, 09:34:42 PM

Title: Front Page News
Post by: pszilard on December 12, 2007, 09:34:42 PM
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.
Title: Re: Front Page News
Post by: albatros on December 12, 2007, 10:55:39 PM
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
Title: Re: Front Page News
Post by: stinkywinky on December 13, 2007, 07:39:46 AM
Another easy option is to put the next code inside your template:

Code: [Select]

<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), &#39;%d/%m/%Y&#39;) 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() .&#39;<BR>&#39;. $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 = &#39;".$id."&#39;");
  
$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 -->

Title: Re: Front Page News
Post by: pszilard on December 15, 2007, 10:16:34 AM
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.
Title: Re: Front Page News
Post by: stinkywinky on December 15, 2007, 04:27:26 PM
Just put the code inside your template!
Title: Re: Front Page News
Post by: marathoner on December 15, 2007, 11:24:55 PM
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.
Title: Re: Front Page News
Post by: Hans on December 16, 2007, 07:44:29 AM
You could also use two templates, one with the code for the frontpage, an one without the code for pages  without news.
Hans
Title: Re: Front Page News
Post by: pszilard on January 03, 2008, 04:56:38 AM
I got it working by creating a Code Section with "display_news_items(4,20,150,0);" inside it.

Thanks for the pointers.