Contribute  :  Support  :  Downloads  :  Forum  :  Links  :  Polls  :  Calendar  :  Directory  :  Advanced Search  
Geeklog The Ultimate Weblog System
Welcome to Geeklog
Friday, May 16 2008 @ 04:23 AM EDT
   

Latest Stories in a Block

GeeklogI 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

Story Options

Latest Stories in a Block | 7 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Latest Stories in a Block
Authored by: Anonymous on Tuesday, October 05 2004 @ 04:52 AM EDT
by the way, if you are searching for nice flags as you used some at that iraq page, you can check out www.3dflags.com, they have a nice collection

---
tokyoahead.com
Latest Stories in a Block
Authored by: keystone430 on Friday, October 15 2004 @ 03:57 PM EDT
Thanks Tom! I just added it to the front page at www.keystonesoldiers.com and it looks good.

Keystone
Latest Stories in a Block
Authored by: mrb42 on Thursday, November 11 2004 @ 08:21 AM EST
For some reason, this wasn't quite working for me... no errors, but the links weren't working, so I did a slight rewrite and simplified it a bit.

    $numStories = 10;
    $result = DB_query("Select sid, title,date FROM {$_TABLES['stories']} WHERE (date <= NOW()) AND (draft_flag = 0) ORDER BY date DESC LIMIT $numStories");
    $nrows = DB_numRows($result);
    for ($i = 1; $i <= $nrows; $i++) {
        $A = DB_fetchArray($result);
        $retval .= '<a href="' . $_CONF['site_url'] . '/article.php?story=' . $A['sid'] . '">' . stripslashes($A['title']) .  '</a><BR>';
}
    return $retval;
Latest Stories in a Block
Authored by: tomw on Thursday, November 11 2004 @ 09:40 AM EST
The reason the links weren't working was that the version I had used the url-rewriting form of the link. Apparently your server does not support this.

You also removed the date of the story. The other thing you removed is the security check, so that all stories are available for all users.

Thanks for sharing your changes for others to use.
Latest Stories in a Block
Authored by: mrb42 on Friday, November 12 2004 @ 09:22 AM EST
I don't use the groups, so it wasn't needed for my site... and as soon as I can figure out how to reformat the date I'm going to add it back (I'm a newb to PHP), I just want the Mon-DD (like the Older Stories Block) instead of the full timestamp...
Latest Stories in a Block
Authored by: tomw on Friday, November 12 2004 @ 10:03 AM EST
In my original query I had:

unix_timestamp(date) AS day

That was for a situation like this. Then you could use

date("M d",$A['day']) and it would be formated like

Nov 12

Look at the date function in php for other variations.

Tom
Latest Stories in a Block
Authored by: mrb42 on Friday, November 12 2004 @ 10:30 AM EST
Thanks!

$numStories = 10;
    $result = DB_query("Select sid, title,unix_timestamp(date) AS day FROM {$_TABLES['stories']} WHERE (date <= NOW()) AND (draft_flag = 0) ORDER BY date DESC LIMIT $numStories");
    $nrows = DB_numRows($result);
    for ($i = 1; $i <= $nrows; $i++) {
        $A = DB_fetchArray($result);
        $retval .=  date("M d",$A['day']) . ' -- <a href="' . $_CONF['site_url'] . '/article.php?story=' . $A['sid'] . '">' . stripslashes($A['title']) .  '</a><BR>';
}
    return $retval;
This is the final version for my site... check it out in action at Northeast Ohio Music