Anyone have Prev/Next Thread / Forum plugin?
-
Is there a plugin that will let you navigate by previous/next thread (when reading a thread) and/or previous/next forum (when looking at a forum)
-
There is now!
Save this in a file, call it
sumting.php
, and drop it into yourmy-plugins
folder. Then put<?php feltopicnav(); ?>
somewhere in a topic template. Not tested, so please tell me if it works.<?php
/*
Plugin Name: Topic Navs;
Plugin URI:
Description: Put <?php feltopicnav(); ?> in a topic template to show links to the previous and next topics. Optional parameters are $nexttext, $prevtext, $betweentext and $lastpost.
Author: fel64
Version: 0.7
Author URI: http://www.loinhead.net/
*/
function feltopicnav( $nexttext = '', $prevtext = '', $betweentext = ' ', $lastpost = true )
{
global $topic_id;
$nexttopic = $topic_id + 1;
$prevtopic = $topic_id - 1;
if( !$nexttext )
$nexttext = topic_title( $nexttopic );
if( !$prevtext )
$prevtext = topic_title( $prevtopic );
if( $lastpost ) {
$nextlink = topic_last_post_link( $nexttopic );
$prevlink = topic_last_post_link( $prevtopic );
} else {
$nextlink = topic_link( $nexttopic );
$prevlink = topic_link( $prevtopic );
}
echo '<a href="' . $prevlink . '">' . $prevtext . '</a>' . $betweentext . '<a href="' . $nextlink . '">' . $nexttext . '</a>';
}
?>you rule.
how about prev / next forums?
I plan on doing something kinda neat with this. you’re definitely getting thanks.
Doesn’t seem to work. I just get the URLS without any linkage.
Could you split this up to just spit out the URLS? like a nexttopic() and prevtopic() ?
that way we could format it how we want (and where we want.)
example: http://blognola.org/fearandloathingbbs/topic.php?id=1&page&replies=1
Ahh, that’ll teach me to remember the difference between get_bbpress_thing() and bbpress_thing(). >_< Sorry.
Replace the code in there now with this.
Set the last parameter to true if you want it to return an array of information. To use this you would use code like this:
<?php $mytopicnavarray = feltopicnav( '', '', ' ', true, true );
echo '<a href="' . $mytopicnavarray['next']['link'] . '">Click here to go to the next topic!</a>'; ?>Use
<?php felforumnav(); ?>
to get the forum navigation in a similar way to the topic navigation. It’s just a simple wrapper for what feltopicnav does, but it’s a bit easier to see what it’s supposed to do. Check the code for possible parameters.I won’t submit this as a proper plugin because the code is awkward. Maybe sometime I’ll recode it or someone else will.
<?php
/*
Plugin Name: Topic Navs;
Plugin URI:
Description: Put <?php feltopicnav(); ?> in a topic template to show links to the previous and next topics, and put in <?php felforumnav(); ?> to get basic next/previous forum navigation. More parameters such as $infoonly available.
Author: fel64
Version: 0.7
Author URI: http://www.loinhead.net/
*/
function feltopicnav( $nexttext = '', $prevtext = '', $betweentext = ' ', $lastpost = true, $infoonly = false, $forumnav = false; )
{
global $topic_id;
$nexttopic = $topic_id + 1;
$prevtopic = $topic_id - 1;
global $forum_id;
$nextforum = $forum_id + 1;
$prevforum = $forum_id - 1;
if( !$nexttext )
if( !$forumnav ) {
$nexttext = get_topic_title( $nexttopic );
} else {
$nexttext = get_forum_name( $nextforum );
}
if( !$prevtext )
if( !$forumnav ) {
$prevtext = get_topic_title( $prevtopic );
} else {
$prevtext = get_forum_name( $prevforum );
}
$prevtext = get_topic_title( $prevtopic );
if( $lastpost ) {
$nextlink = get_topic_last_post_link( $nexttopic );
$prevlink = get_topic_last_post_link( $prevtopic );
} else {
if( !$forumnav ) {
$nextlink = get_topic_link( $nexttopic );
$prevlink = get_topic_link( $prevtopic );
} else {
$nextlink = get_forum_link( $nextforum );
$prevlink = get_forum_link( $prevforum );
}
}
if( $infoonly ) {
$topicnavinfo['next']['title'] = $nexttext;
$topicnavinfo['next']['link'] = $nextlink;
$topicnavinfo['prev']['title'] = $prevtext;
$topicnavinfo['prev']['link'] = $prevlink;
return $topicnavinfo;
} else {
echo '<a href="' . $prevlink . '"> « ' . $prevtext . '</a>' . $betweentext . '<a href="' . $nextlink . '">' . $nexttext . ' » </a>';
}
}
function felforumnav( $nexttext = '', $prevtext = '', $betweentext = ' ', $infoonly = false )
{
$fni = feltopicnav( $nexttext, $prevtext, $betweentext, false, true, true );
if( $infoonly ) {
return $fni;
} else
echo '<a href="' . $fni['prev']['link'] . '"> « ' . $fni['prev']['title'] . '</a>' . $betweentext . '<a href="' . $fni['next']['link'] . '"> « ' . $fni['next']['title'] . '</a>';
}
}
?>Excellent… Had a couple typos in there that I fixed, will post code when I’m done.
I’m actually trying to make a theme based on old dial-up BBSs. Fun, fun, fun. The menu is the hardest part, trying to get different options to show up depending on what page you’re on (forum/topic/etc…)
Here’s what I have so far:
http://fearandloathingbbs.com/forum/
Not quite ready for prime time .
Does anyone know why I would get Plugin could not be activated; it produced a Fatal Error when trying activate this as a plugin? I’m running bbPress 0.8.3…
A fatal error would normally be a PHP fatal error. Do you have access to PHP logs to see what the trouble might be? If not, you can set up some custom logging.
And, are you running WordPress as well? Which version, if so.
- You must be logged in to reply to this topic.