Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to restrict number of Latest Discussions on front page


  • glanceup
    Member

    @glanceup

    Hi. I’m using 9.0.1. I would like to restrict the number of Latest Discussions showing to 5. How do I do this? I don’t see anything in the bb-config file and the Front Page Topics plugin doesn’t seem to work with 9.0.1…

    Your help appreciated.

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

  • _ck_
    Participant

    @_ck_

    Front page topics plugin isn’t working? Hmm. Should be.

    I have a modification I’ve done somewhere…

    Try this:

    // fix number of front page topics
    function bb_custom_topic_limit($limit) {
    switch (bb_get_location()) :
    case 'front-page': $limit=5; break;
    case 'forum-page': $limit=10; break;
    case 'tag-page': break;
    case 'topic-page': $limit=15; break;
    case 'feed-page': break;
    case 'search-page': break;
    case 'profile-page': break;
    case 'favorites-page': break;
    case 'view-page': $limit=10; break;
    case 'stats-page': break;
    case 'login-page': break;
    default: $limit=15;
    endswitch;
    return $limit;
    }
    add_action( 'bb_get_option_page_topics', 'bb_custom_topic_limit',200);

    // required to fix for custom topic limits to calculate correct page jumps
    function fix_post_link ($link,$post_id) {
    global $topic;
    remove_action( 'bb_get_option_page_topics', 'bb_custom_topic_limit' );
    if ($topic && $topic->topic_last_post_id==$post_id) {
    $topic_id=$topic->topic_id;
    $page=get_page_number( $topic->topic_posts );
    } else {
    $bb_post = bb_get_post( get_post_id( $post_id ) );
    $topic_id=$bb_post->topic_id;
    $page = get_page_number( $bb_post->post_position );
    }
    return get_topic_link( $topic_id, $page ) . "#post-$post_id";
    }
    add_filter( 'get_post_link','fix_post_link',10, 2);


    glanceup
    Member

    @glanceup

    ck — Into what file and where do I paste that code? Thanks. PS I am using bbPress 9.0.1


    citizenkeith
    Participant

    @citizenkeith

    glanceup: Just cut and paste it into a plugin template. Here’s what I did (apologies to _ck_ if the headers aren’t quite right):

    <?php

    /*

    Plugin Name: Fix Number of Front Page Topics

    Plugin URI: http://bbpress.org/forums/topic/how-to-restrict-number-of-latest-discussions-on-front-page

    Description: Fix Number of Front Page Topics

    Author: _ck_

    Author URI: http://bbshowcase.org/

    Version: 0.1

    */

    // fix number of front page topics
    function bb_custom_topic_limit($limit) {
    switch (bb_get_location()) :
    case 'front-page': $limit=5; break;
    case 'forum-page': $limit=10; break;
    case 'tag-page': break;
    case 'topic-page': $limit=15; break;
    case 'feed-page': break;
    case 'search-page': break;
    case 'profile-page': break;
    case 'favorites-page': break;
    case 'view-page': $limit=10; break;
    case 'stats-page': break;
    case 'login-page': break;
    default: $limit=15;
    endswitch;
    return $limit;
    }
    add_action( 'bb_get_option_page_topics', 'bb_custom_topic_limit',200);

    // required to fix for custom topic limits to calculate correct page jumps
    function fix_post_link ($link,$post_id) {
    global $topic;
    remove_action( 'bb_get_option_page_topics', 'bb_custom_topic_limit' );
    if ($topic && $topic->topic_last_post_id==$post_id) {
    $topic_id=$topic->topic_id;
    $page=get_page_number( $topic->topic_posts );
    } else {
    $bb_post = bb_get_post( get_post_id( $post_id ) );
    $topic_id=$bb_post->topic_id;
    $page = get_page_number( $bb_post->post_position );
    }
    return get_topic_link( $topic_id, $page ) . "#post-$post_id";
    }
    add_filter( 'get_post_link','fix_post_link',10, 2);

    ?>


    citizenkeith
    Participant

    @citizenkeith

    However, fel64′s “Page” plugin doesn’t work after activating this one:

    http://bbpress.org/forums/topic/go-to-last-post-in-topic


    glanceup
    Member

    @glanceup

    Oh, excitement! That seems to work just fine. Thank you.


    citizenkeith
    Participant

    @citizenkeith

    Thanks to Sam, I learned that the Freshness column links to the latest post, so fel64′s Page plugin is no longer necessary.

    However, when I activate _ck_’s Front Page Posts plugin, the freshness column links to a page without any posts.

    _ck_ (or anybody who wants to troubleshoot) can contact me for a login and password for my forum. kamera [at] gmail will do the trick.


    _ck_
    Participant

    @_ck_

    My educated guess would be because fel64′s plugin is grabbing the link within the title, so the plugin that alters the page count is not getting unhooked yet.

    Try adding on a new line after global $topic; in fel64′s plugin:

    remove_action( 'bb_get_option_page_topics', 'bb_custom_topic_limit', 200);

    It’s occurred to me there might be a bug in my plugin where I don’t have that matching ,200 on the end of the same remove_action line. If I remember correctly, actions have to be unhooked with matching priority numbers to how they were added. So maybe try adding the ,200 also.

    Remember that bbPress’s “topics per page” setting must be set to the actual number of posts you want listed on a topic page.


    citizenkeith
    Participant

    @citizenkeith

    That worked! Thanks _ck_!!

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

You must be logged in to reply to this topic.