Jump to content

Show 3 Latest Announcements?


tommyquang

Recommended Posts

<?php
$query = "SELECT * from tblannouncements WHERE published='on' ORDER BY
date DESC";
$result=mysql_query($query);
$num=0;
while($data = mysql_fetch_array($result) and $num<3  ) {
$num = $num +1;

$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);

echo("$date <br />");
echo(" - <b>$title</b> -<br />");
echo("$announcement");
echo('<br />___________________________<br />');

}
?>

 

You can insert this code in template using {php} tags or simpler,

create a file like announcements.php paste the code there, make any changes

you want with the format (font, color, css, etc) and then just include the file

using {php}include announcements.php{/php}

Link to comment
Share on other sites

  • 2 years later...

Below code are use with smarty and SEF urls. Hopefuly englighten who ever stucked with $announcements loop.

 

{if $announcements}
<div class="latest_news">
{foreach from=$announcements item=announcement name=foo}
 {if $smarty.foreach.foo.index < 3}
    <div class="n_date">{$announcement.date}</div>
    <div class="n_tite"><a href="{if $seofriendlyurls}announcements/{$announcement.id}/{$announcement.urlfriendlytitle}.html{else}announcements.php?id={$announcement.id}{/if}">{$announcement.title}</a></div>
    <div class="n_para">{$announcement.text|strip_tags|truncate:100:"..."}</div>
    <div class="n_rear"><a href="{if $seofriendlyurls}announcements/{$announcement.id}/{$announcement.urlfriendlytitle}.html{else}announcements.php?id={$announcement.id}{/if}"">read more</a></div>
  {/if}
{/foreach}
{/if}

 

you can use index to control the loop condition.

 

  {if $smarty.foreach.foo.index < 3}

means you will get 3 latest announcements.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated