Welcome to Geeklog Thursday, November 23 2017 @ 11:53 am EST

Latest Stories in a Block

  • Contributed by:
  • Views: 7,317
Geeklog I decided to put the titles for the latest stories in the static page centerblock on one of my sites. Here is the code to do this, just place it in a static page, set the centerblock option, set the execute php option to 'execute PHP (return)' and pretty it up however you want. It will display the last date and titles of the last 15 (or whatever you set the $numstories variable to) stories.

Anyway here is the code ...


$numstories = 15;
$sql = "SELECT *,unix_timestamp(date) AS day";
$sql .= " FROM {$_TABLES['stories']}";
$sql .= " WHERE (date <= NOW()) AND (draft_flag = 0)";
$sql .= " AND (";
if (!empty ($_USER['uid'])) {
    $groupList = '';
    foreach ($_GROUPS as $grp) {
        $groupList .= $grp . ',';
    }
    $groupList = substr ($groupList, 0, -1);
    $sql .= "(owner_id = {$_USER['uid']} AND perm_owner >= 2) OR ";
    $sql .= "(group_id IN ($groupList) AND perm_group >= 2) OR ";
    $sql .= "(perm_members >= 2) OR ";
}
$sql .= "(perm_anon >= 2))";

$order = " ORDER BY date DESC LIMIT $numstories";

$recs = DB_query($sql . $order);
$nrows = DB_numRows($recs);

$display .= '<ul>';

for ($x = 0; $x < $nrows; $x++) {
    $A = DB_fetchArray($recs);
    $display .= '<li>' . $A['date'] . "   ";
    $display .= '<a href="' . $_CONF['site_url'] . '/article.php/' . $A['sid'] . '">'
             . stripslashes($A['title']) . '</a>';
    $display .='</li>';    

}
                            
$display .= '</ul>';

return $display;

You can see it in action at the Iraq page. Enjoy TomW