Skip to:
Content
Pages
Categories
Search
Top
Bottom

Include sub-forum topics in parent forum loop

  • @dryan1144

    Participant

    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 10 replies - 1 through 10 (of 10 total)
  • @robin-w

    Moderator

    ‘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

    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

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

    @dryan1144

    Participant

    Thanks Robin I will have a look at your code.

    @robin-w

    Moderator

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

    @lemolee88

    Participant

    please help! it’s important for me! i have the same problem!

    @lemolee88

    Participant

    @robin-w it’s not work

    @robin-w

    Moderator

    I’m afraid I don’t have time at the moment to do lots of coding for others

    @netweb

    Keymaster

    With the existing code in the original topic and along with this snippet I had else where you should be fine to put it all together:

    To get the child/sub forums from the current forum page use bbp_forum_get_subforums() and then pass those ID’s to post_parent__in (Note the double underscore). You can also go the other way to get ‘parents’ of the current forum with bbp_get_forum_ancestors().

    e.g. To include forum ID’s 2, 5, 12 and 14 add the post_parent__in

    
    if ( bbp_has_topics( array( 'orderby' => 'rand', 'posts_per_page' => 1, 'post_parent__in' => array( 3, 5, 12, 14 ) ) ) ) {

    e.g. To exclude forum ID’s 7, 11, 19 and 21add the post_parent__not_in

    
    if ( bbp_has_topics( array( 'orderby' => 'rand', 'posts_per_page' => 1, 'post_parent__not_in' => array( 7, 9, 11, 19 ) ) ) ) {

    @lemolee88

    Participant

    @netweb sorry i am not good at php and english, can you give me The complete code?

    Very sorry to have wasted your time. But it is really important to me.In addition to you, I do not know who can help me!

    @lemolee88

    Participant

    @netweb Waiting…

    @netweb

    Keymaster

    I am sorry, I am not writing custom plugins for people for free, let alone your assumption that that is what you expect, not going to happen.

    If you need some custom code written post an advert on http://jobs.wordpress.net

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Skip to toolbar