Welcome to Geeklog, Anonymous Sunday, December 22 2024 @ 12:28 am EST

Geeklog Forums

Link to first story in topic?


Kiwi

Anonymous
What I would like to do is have a link on a static page that will link to the very first story in a topic. So that everytime a story is added to that topic, that is the story that the link points too.

Can this be accompished? If so how? Much help would be great thanks!
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
I think i've posted this before, but can't remember. Just added "limit 1" to return only the last story submitted. Place this function in your gldir/system/lib-custom.php and call it from your PHP enabled staticpage.
Text Formatted Code

//returns the single latest story from a specific topic
function phpblock_lastStory(){
    global $_TABLES, $_CONF;
    $topic= 'yourTopicId';
    $retval = '';
    //query stories by tid
    $A = DB_query("SELECT title, sid FROM {$_TABLES['stories']}
        WHERE tid='$topic'
        AND (date <= NOW()) AND (date >= (DATE_SUB(NOW(), INTERVAL 30 DAY)))
        AND (draft_flag = 0)" . COM_getPermSQL( 'AND' )
        . "ORDER BY date DESC LIMIT 1");
    if (DB_numRows($A) >= 1){
        //format results and display
        $retval .= '<h1 class="item-title">Your heading</h1>' . LB
            . '<ul>' . LB;
        while ($B = DB_fetchArray($A)){
            $articleUrl = COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $B['sid'] );
            $retval .= '<li><b>→</b>';
            $retval .= '<a href="' . $articleUrl . '">' . stripslashes( $B['title']) . '</a>';
            $retval .= '</li>' . LB;
        }
        $retval .= '</ul>' . LB;
    }
    return $retval;
}



 
 Quote

kiwi

Anonymous
thanks but i get an error when i try that...

parse error, unexpected $ in /togeeklog/public_html/staticpages/index.php(56) : eval()'d code on line 1

the only thing i have to change is the topic id right?
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
yes, just change the topic id to yours... note: use the ID not the Name.
as far as the error goes, I know the function works so you must have a syntax error in the staticpage where you called the function.

note: the staticpage must be PHP enabled; and watch how you use your open and close tags. A common error is to place an php open tag at the beginning of the staticpage when it is not necessary if all you are placing in the editor is PHP.
Hope that helps.
 Quote

kiwi

Anonymous
ya i changed that...

but i still got the error. So i thought, maybe i am calling the function wrong.

i was using "phpblock_lastStory()" and got

Parse error: parse error, unexpected $ in /home/thenake/public_html/staticpages/index.php(56) : eval()'d code on line 1

then i tried "phpblock_lastStory" cause thats how i called a phpblock function. and thought w00t thats it! but then i got the same error:

then i tried with a (); at the end , no error but no results... i am going to look at the code again for anything i missed (like a missing quote or : just in case).
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
post your staticpage code and I'll see about it for you... e.g.,
Text Formatted Code

//begin php enabled staticpage (set to execute) editor window

?>
insert some html here
<?php

$firststory = phpblock_lastStory();
echo $firststory;

?>
more html here
<?php

//end staticpage editor window


 
 Quote

Kiwi

Anonymous
ok so it exports a link to first story which then has to be clicked on, and not the first story itself, i get it now.

ok so i have to work that into the page it self and then have the link outputed, ok thanks.
 Quote

All times are EST. The time is now 12:28 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content