Skip to:
Content
Pages
Categories
Search
Top
Bottom

Show only Parent Forums

  • I want to show only the very top level forums on my front page. I have tried:

    <?php if ( bb_forums("depth=1") ) : ?>

    But that didn’t work and all the forums still show up. I only want to show the very top level, so for example if I have the following forums:

    Main
    - Sub Forum 1
    - Sub Forum 2
    --- Sub Forum 2.1
    --- Sub Forum 2.1
    - Sub Forum 3
    Community
    - Sub Forum 1
    - Sub Forum 2
    --- Sub Forum 2.1
    --- Sub Forum 2.1
    - Sub Forum 3

    Only Main and Community would appear on the home page.

    Thanks.

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

  • kevinjohngallagher
    Member

    @kevinjohngallagher

    You’ll need to code a custom loop for that I’m afraid.

    @kevinjohngallagher

    Any help making one? I don’t understand the loop in bbPress very well.

    Thanks


    zaerl
    Participant

    @zaerl

    Open front-page.php. Locate:

    if(bb_forums())

    (line 47 in kakumei) change it in:

    if(bb_forums(array('where' => 'where forum_parent = 0')))

    Have a nice day.


    zaerl
    Participant

    @zaerl

    Change the f***ing HTML entity of the above post to the corresponding angular bracket. This forum bug makes me mad.

    Cool works great. How do I do the same for the sub forums page where the tag looks like this:

    <?php if ( bb_forums( $forum_id ) ) : ?>

    Any updates? Looking to get this implemented asap. Thanks.


    kevinjohngallagher
    Member

    @kevinjohngallagher

    What code did you try on the sub forum pages nad we can try and help :)

    I tried the code zaerl posted, but it when viewing forums it requires the $forum_id within the function to display the correct stuff otherwise it will show the same as the front page and not the selected forums subforums. I need to use $forum_id with the array posted so I only get the top level forums within the chosen forum.

    I tried doing this to see if it would combine the two:

    if(bb_forums($forum_id, array(‘where’ => ‘where forum_parent = 0’)))

    but it just showed all the forums for that forum and not just the parents


    zaerl
    Participant

    @zaerl

    if(bb_forums(array(‘where’ =] “where forum_parent = $forum_id”)))

    Substitute the square bracket ] with the angular bracket. For great justice.

    This only works for forums that have subforums. If I have a forum that is just top level and has no subforums when I view it it blows up saying Invalid argument supplied for foreach() in /nfs/c03/h05/mnt/52704/domains/paperviewmagazine.com/html/forums/bb-includes/functions.bb-forums.php on line 84

    If I switch the original if statement on instead it doesnt break, so it’s defo the new code. Any ideas? Thanks


    kevinjohngallagher
    Member

    @kevinjohngallagher

    Ok, so you’re trying to do something that bbPress can’t natively do.

    You’re presuming, and we can all see why, that because this is forum software that it has native parent/child relationships; when it doesn’t really.

    I’ve always found the best thing to do is to write my own forum subroutine in a page.

    if ( bb_forums( $forum_id ) )

    {

    while ( bb_forum() )

    {

    global $forum;

    global $forum_id;

    print_r($forum);

    // I output my own code here using

    // $forum->forum_name

    // $forum->posts

    // To show children of forum

    if($forum->forum_parent == $forum_id || empty( $forum_id))

    {

    //Output code here, it’s a child or you’re on the front page

    }

    }

    }

    To re-iterate, I’m coding the above from memory, so if there are errors you’ll need to check them yourself :)


    kevinjohngallagher
    Member

    @kevinjohngallagher

    oh for goodness sake, that code bug is really getting on my tits.

    Driz, the main thing to remember is this. these forums are aimed at making the WordPress support forums. Once you try and venture outside the functionality they have, you’re going ot hit issues which will need you to be able to read/write/investigate the source PHP files.


    zaerl
    Participant

    @zaerl

    Yes I know. Unfortunately I had to fight with that piece of code also in my plugin zaerl Visibility. bbPress doesn’t allow zero forums.

    I think I found a much better way to get around it. Just wrap the new tag with the old tag, as it check for the forums if none then don’t run the new code.

    <?php if ( bb_forums( $forum_id ) ) : ?>

    <?php if(bb_forums(array('where' => "where forum_parent = $forum_id"))) : ?>

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