Welcome to Geeklog, Anonymous Sunday, May 26 2024 @ 08:02 pm EDT

Geeklog Forums

Article Navigation


Status: offline

ByteEnable

Forum User
Full Member
Registered: 10/20/03
Posts: 138
I wanted a article nav similar to mambo, so here it is:

Add the new code to lib-story.php. Its in the STORY_renderArticle function, around line 126.

Text Formatted Code

if( $index == 'n' )
    {
// START NEW CODE
        $result = DB_query("SELECT `sid` FROM `gl_stories` WHERE `tid` = '" . $A['tid'] . "' AND `sid` < '" . $A['sid'] . "' ORDER BY `sid` DESC LIMIT 1");
        $PrevStory = DB_fetchArray($result);
        $result = DB_query("SELECT `sid` FROM `gl_stories` WHERE `tid` = '" . $A['tid'] . "' AND `sid` > '" . $A['sid'] . "' ORDER BY `sid` LIMIT 1");
        $NextStory = DB_fetchArray($result);

        $StoryNavTopic = ucfirst($A['tid']);
        if ( $PrevStory[0] == '' ) {
                $article->set_var('PrevStory','<td class="StoryNav"></td>');
        }
        else {
                $article->set_var('PrevStory','<td class="StoryNav"><BR><A title="Read previous article in “'. $StoryNavTopic . '”" class="PageNav" href="/article.php/'. $PrevStory[0] . '">«Prev</a></td>');
        }
        if ( $NextStory[0] == '' ) {
                $article->set_var('NextStory','<td class="StoryNav"></td>');
        }
        else {
                $article->set_var('NextStory','<td class="StoryNav"><BR><A title="Read next article in “' . $StoryNavTopic . '”" class="PageNav" href="/article.php/'. $NextStory[0] . '">Next»</a></td>');
        }
//END NEW CODE
        $article->set_var( 'story_title', stripslashes( $A['title'] ));

 


Next update your theme (storytext.thtml) with the PrevStory and NextStory variables.

Text Formatted Code

</tr>
{story_bodyhtml}
{PrevStory}{NextStory}
</table>

 


You will also need to edit your CSS with your own style. If anyone knows how to optimize those two MySQL queries, please share. You can see this in action at LinuxElectrons.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Haven't tried it, but why are you sorting by "sid"? With the editable story IDs introduced in 1.3.10, the articles may come out in an odd order ... Better sort by date.

bye, Dirk
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 10/20/03
Posts: 138
Yeah, I looked at the date. But wouldn't I have convert that ASCII back to unix time format? If so, how easy is that?

 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Nope, MySQL already does that for you. To quote from index.php:
Text Formatted Code
$sql .= "ORDER BY featured DESC, date DESC";
 

This is how the stories are sorted on the index page. No conversion necessary.

bye, Dirk
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 10/20/03
Posts: 138
Thanks for the tip Dirk. I've already implemented it. I just replaced all the 'sid' with date.
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 10/20/03
Posts: 138
Here is an update for the database queries for those that have used this code.

Text Formatted Code

 $result = DB_query("SELECT `sid` FROM `gl_stories` WHERE `tid` = '" . $A['tid'] . "' AND `date` < '" . $A['date'] . "' ORDER BY `date` DESC LIMIT 1");
        $PrevStory = DB_fetchArray($result);
        $FutureDate = date( "Y-m-d H:i:s", time() );
        $result = DB_query("SELECT `sid` FROM `gl_stories` WHERE `tid` = '" . $A['tid'] . "' AND `date` > '" . $A['date'] . "' AND `date` < '" . $FutureDate . "'ORDER BY `date` LIMIT 1");
        $NextStory = DB_fetchArray($result);

 
 Quote

All times are EDT. The time is now 08:02 pm.

  • 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