not sure where you want this to show??
I want this to show on single-topic’s page
Apparently it’s a blog-type queue. There is a queue by the fresh date when the post was written.
And how want you – by the most recent topic or the most recent comment?
I made the list
<?php $args = array( 'post_type' => 'topic', 'post_parent' => bbp_get_forum_id() ); $loop = new WP_Query( $args ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php echo get_the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile;?>
This gives me all the topics under the current topic’s forum (I’m on single-topic.php)
Is there a way I could limit the list to 5 links (that’s easy, post_per_page = 5
) but on top of that only show the adjacent posts?
Topic 3 link
Topic 4 link
Topic 5 link <----- I'm here
Topic 6 link
Topic 7 link
In the above example, it’s showing me 2 previous adjacent posts and to next adjacent posts
What happens is if I set post_per_page
to 5 then this happens
Topic 1 link
Topic 2 link
Topic 3 link
Topic 4 link
Topic 5 link <----- I'm here
The current link is always last, I realized this is more of a wordpress question but I’d like to try my luck here since I already opened a thread
@athep – have you solved this ?
I think I got timed out, not sure if my reply was deleted.
I haven’t solved it yet, I did find two promising threads though but I couldn’t make sense of it.
just had a quick look
this should get you close, totally untested !!
<?php $args = array( 'post_type' => 'topic', 'post_parent' => bbp_get_forum_id() );
$loop = new WP_Query( $args );
//get the current topic id or maybe depending in where you are putting this - bbp_get_reply_topic_id or bbp_get_reply_id()
$topic_id = bbp_get_topic_id() ;
while ( $loop->have_posts() ) : $loop->the_post();
$cur_id = get_the_ID();
if ($cur == $topic_id) {
$prev = get_previous_post() ;
$prev_id = $prev->ID ;
$next = get_next_post();
$next_id = $next->ID ;
break ;
}
endwhile;
//so you now have $cur_id, $prev_id and $next_id
//so create 3 lines
if (!empty ($prev_id)) {
$permalink = get_permalink($prev_id) ;
$title = get_the_title ($prev_id) ;
echo '<a href="'.$permalink.'">'.$title.'</a>' ;
}
if (!empty ($cur_id)) {
$permalink = get_permalink($cur_id) ;
$title = get_the_title ($cur_id) ;
echo '<a href="'.$permalink.'">'.$title.'</a>' ;
}
if (!empty ($next_id)) {
$permalink = get_permalink($next_id) ;
$title = get_the_title ($next_id) ;
echo '<a href="'.$permalink.'">'.$title.'</a>' ;
}
?>
Thank you Robin,
I tried this, I was inserting this in single-topic.php so I was not sure which one would work.
$topic_id = bbp_get_topic_id() ;
works well, the only issue is that once it nears the end, the other forums start leaking in, if prev or next is empty they leak in
Otherwise it’s working as expected, also I fixed if ($cur == $topic_id) {
to if ($cur_id == $topic_id) {
hmmm…not sure about the ‘leak in’ bit, how are lines being displayed if $prev etc. is blank?
you could add a check
so set
$forum_id = bbp_get_forum_id() ;
above the while statement and then check at the appropriate point
if (wp_get_post_parent_id($prev_id) != $forum_id) {
etc.
}
I set $forum_id = bbp_get_forum_id() ;
and change these two
if (!empty ($prev_id) && wp_get_post_parent_id($prev_id) == $forum_id) {
and
if (!empty ($next_id) && wp_get_post_parent_id($next_id) == $forum_id) {
Notice the equal sign, that solved the problem!
Thank you so much Robin!
EDIT:
The last topic links in every forum somehow get left behind, only the last ones.. I’ll tinker around and post my findings
great, and yes please post the completed functioning code once you have got it working !!