Skip to:
Content
Pages
Categories
Search
Top
Bottom

Include sub-forum topics in parent forum loop


  • dryan1144
    Participant

    @dryan1144

    Out of the box, bbpress shows topics from a particular forum when you are on that forum’s archive page. Makes sense. If that forum has a sub-forum, it will link to those sub-forums, but it won’t show the actual topics from that sub-forum.

    I’m trying to modify the default bbpress loop on a forum page (loop-topics.php) to include the sub-forum topics.

    Here’s an explanation:

    Forum A
    Sub-forum A1
    Sub-forum A2
    Forum B
    Sub-forum B1
    Sub-forum B2
    So when viewing Forum A’s archive page, I’d like to show topics from Forum A, sub-forum A1 and sub-forum A2.

    The code needs to be dynamic in order to work with whatever parent forum archive a user is on.

    You can pass wp_query args into bb_has_topics(), but I can only only come up with code that shows topics from one forum – not multiple forums.

    To better explain what I’m working with, here’s an example of a loop that grabs topics from the parent forum:

    
    <?php
    
    $parents = get_post_ancestors( $post->ID );
    
    $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
    
    $parent = get_page( $id );
    
    ?>
    
    <?php $bbp_loop_args = array('post_parent' => $parent->ID, 'post_type' => 'topic'); ?>
    
    <?php if ( bbp_has_topics($bbp_loop_args) ) : ?>
    
        <?php while ( bbp_topics() ) : bbp_the_topic(); ?>
    
            <?php bbp_get_template_part( 'loop', 'single-topic' ); ?>
    
        <?php endwhile; ?>
    
    <?php endif;?>
    

    Any ideas on how this can be achieved?

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robin W
    Moderator

    @robin-w

    ‘You can pass wp_query args into bb_has_topics(), but I can only only come up with code that shows topics from one forum – not multiple forums.’

    I’m afraid I don’t have time at the moment to do lots of coding for others, but take a look at this plugin

    http://www.rewweb.co.uk/bbp-private-groups/

    Look at includes/topics.php for how I did this for private groups – called pg_has_topics, it may give you some help – I used ‘post__in’ to create a list of topics to display

    So you could do a coupe of loops to create this list and the pass that to the bbp_has_topics function.

    ‘post__in’ is realy, useful sometimes

    see

    http://codex.wordpress.org/Class_Reference/WP_Query


    dryan1144
    Participant

    @dryan1144

    Thanks Robin I will have a look at your code.


    Robin W
    Moderator

    @robin-w

    great – if you fix it, please post the solution here to help others !

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.