Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

List of topic pages next to forum topic (bp_the_topic_pagination) (7 posts)

Started 3 months, 2 weeks ago by: notpoppy

  • Profile picture of notpoppy notpoppy said 3 months, 2 weeks ago:

    In a forum, I would like to have a list of the pages in each topic next to the link to it. That way users can jump into the last page of a topic if they wish without having to go through the first page.

    In topic.php (groups/single/forum) the pagination is created using:

    <?php bp_the_topic_pagination() ?>

    Is there a way to make this work in forums-loop.php to create the result I’m trying to achieve?

  • Profile picture of notpoppy notpoppy said 3 months, 2 weeks ago:

    Am still trying to find out how to do this. I’ve had a look at various themes and not found one that has it.

    Can anyone at least tell if it’s possible to do this with Buddypress?

  • Profile picture of notpoppy notpoppy said 1 month, 3 weeks ago:

    I still can’t figure out how or if this is possible – can anyone help?

  • Profile picture of Boone Gorges Boone Gorges said 1 month, 3 weeks ago:

    Anything’s possible ;)

    You won’t be able to do it with bp_the_topic_pagination() because that function requires that you are inside of a single topic loop, which you’re not.

    Try something like:

    global $forum_template;
    
    	$per_page = 5;
    	$total_posts = $forum_template->topic->topic_posts;
    
    	$pag_links = paginate_links( array(
    		'base'      => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int) $per_page ), bp_get_the_topic_permalink() ),
    		'format'    => '',
    		'total'     => ceil( (int) $total_posts / (int) $per_page ),
    		'mid_size'  => 1
    	) );
    	echo $pag_links;
  • Profile picture of notpoppy notpoppy said 1 month, 3 weeks ago:

    @boonebgorges Thanks for the reply!

    I’m not quite sure how to use your solution, though. is it something that goes in functions.php? If so, how do I then use it in the theme?

  • Profile picture of Boone Gorges Boone Gorges said 1 month, 2 weeks ago:

    If you want to use it in a theme, try putting it in a function wrapper and then calling that function in your template. In functions.php:

    function bbg_forum_pag() {
            global $forum_template;
    
    	$per_page = 5;
    	$total_posts = $forum_template->topic->topic_posts;
    
    	$pag_links = paginate_links( array(
    		'base'      => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int) $per_page ), bp_get_the_topic_permalink() ),
    		'format'    => '',
    		'total'     => ceil( (int) $total_posts / (int) $per_page ),
    		'mid_size'  => 1
    	) );
    	echo $pag_links;
    }

    Then in your template:
    <?php bbg_forum_pag() ?>

  • Profile picture of notpoppy notpoppy said 1 month, 2 weeks ago:

    @boonebgorges Works perfectly – thanks very much!