Skip to:
Content
Pages
Categories
Search
Top
Bottom

limit forums included in latest discussions

  • I would like to limit the forums being included in the latest discussions section. More accurately, I wish to specifically exclude a forum. Anyone have any ideas on how to do this in the template?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Yup! Find this (or similar) codeblock in your theme’s front-page.php.

    <tr<?php topic_class(); ?>>
    <td><a href="<?php topic_link(); ?>"><?php topic_title(); ?></a></td>
    <td class="num"><?php topic_posts(); ?></td>
    <td class="num"><?php topic_last_poster(); ?></td>
    <td class="num"><small><?php topic_time(); ?></small></td>
    </tr>

    Around it put

    <?php if( $topic->forum_id != 666 ) { ?>
    ... that code block ...
    <?php } ?>

    You will probably want to change 666 to whatever forum id you actually want to exclude. You can put any conditional logic you like inside those if( … ) brackets, so for example to filter for two forums you would put if( $topic->forum_id != 666 && $topic->forum_id != 999 ). Hope that helps.

    works perfectly.

    This still works! I’m using 1.0.1

    This is how my code looks like:

    <?php if( $topic->forum_id != 29 ) { ?>

    <tr<?php topic_class(); ?>>

    <td><?php bb_topic_labels(); ?> “><?php topic_title(); ?><?php topic_page_links(); ?></td>

    <td class=”num”><?php topic_posts(); ?></td>

    <!– <td class=”num”><?php bb_topic_voices(); ?></td> –>

    <td class=”num”><?php topic_last_poster(); ?></td>

    <td class=”num”>“><?php topic_time(); ?></td>

    </tr><?php }?>

    Thanks


    deadlyhifi
    Participant

    @tomdebruin

    you can do this with a plugin if you like.

    function filter_front_page_topics($where){
    $exclude_forums=array ("3"); // enable this to manually specify specific forums by id #
    if ( is_front() ) {foreach($exclude_forums as $forum) { $where.=" AND forum_id != ".$forum." "; }}
    return $where;
    }
    add_filter( 'get_latest_topics_where', 'filter_front_page_topics');
    add_filter( 'get_latest_posts_where', 'filter_front_page_topics');

    If you have front page paging (1,2,3,4 etc) then the paging count will be wrong. You need to edit the bb-includes/function.bb-template.php file

    function bb_latest_topics_pages() {
    global $page;
    static $bb_latest_topics_count;
    if (!$bb_latest_topics_count) {
    global $bbdb;
    $bb_latest_topics_count = $bbdb->get_var('SELECT COUNT(<code>topic_id</code>) FROM <code>' . $bbdb->topics . '</code> WHERE <code>topic_open</code> = 1 AND <code>topic_status</code> = 0 AND <code>topic_sticky</code> != 2 AND <code>forum_id</code> != 3;');
    }
    echo apply_filters( 'bb_latest_topics_pages', get_page_number_links( $page, $bb_latest_topics_count ), $bb_latest_topics_count );
    }

    Note the addition of AND "forum_id" != 3 to the query.

    EDIT: just noticed that use of backticks in the code has been turned into <code>, so amend as necessary.


    deadlyhifi
    Participant

    @tomdebruin

    In fact, it’s important to do it the way I mention, because just checking for forum id when outputting will still count the topics, therefore the number of topics appearing on the page will be inconsistent.

    e.g. If you have 5 topics in the forum you are not showing, and output the latest 50 on the front-page (Reading Settings > Items per page). You’ll actually get 45 listed.

    Somehow both of your codes doesnt work.


    deadlyhifi
    Participant

    @tomdebruin

    I find that very odd. As it’s working perfectly well for me. Did you put function filter_front_page_topics($where) in a plugin and activate it?

    Yeah ! It works by doing that. Thanks!

    But Is there a way to add to the query ? If there is a Forum Parent (ie, if the post lies in a subforum) I dont want to display it.


    deadlyhifi
    Participant

    @tomdebruin

    Not sure about that since I don’t have any sub forums.

    Have you tried adding to $exclude_forums? Like this $exclude_forums=array ("3", "4","6");?

    Ah but I use Buddypress and when users create groups in bp, automatical Subforums are created (Under the Parent forum id 1) in BbPress. But if I hide forum 1 (The parent), the other forum topics will still show in the latest discussions.

    And Its too painful to go and edit this afterwards. It must be automatic.

    I got some if Statement working with the forum loop. I excluded some subforums showing by using:

    `<?php if ( bb_forums() ) : ?>

    <?php while ( bb_forum() ) : global $forum; if ($forum->forum_parent != 0) continue; ?>

    <!– insert forum stuff to be looped –>

    <?php endwhile; ?>

    <?php endif; // bb_forums() ?>`

    but I cant get it working with topics.


    r-a-y
    Participant

    @r-a-y

    Sorry to bump an old topic, but I just wrote a writeup on the BuddyPress forums detailing how to hide BuddyPress group forums on an external bbPress install:

    https://buddypress.org/forums/topic/how-to-hide-bbpress-forums-from-users-while-allowing-forums-in-buddypress-groups#post-33582

    This addresses anandasama’s problem.

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