Skip to:
Content
Pages
Categories
Search
Top
Bottom

custom topics count for different pages that doesn’t break last post

  • @_ck_

    Participant

    The front page topics plugin was driving me crazy because I really did want to have a different number of topics for the front page, forum pages, view pages, while leaving the posts per topic page alone and not have to hack the core.

    But there is a huge flaw in the fundamental design in that if you force bbpress to see a different number of topics-per-page, it will calculate the last post page entirely wrong, based on the page IT’S ON, vs the destination page.

    ie. front page set to 50 topics, posts-per-topic-page set to 25, last post is #30 on the page -> bbpress will calculate the page number for the last post as PAGE ONE off the front page, because that’s what the topic count is set to for the front page.

    This got me really annoyed so I researched the heck out of it and figured out this trick – it’s nasty but works (for 8.2.1 at least).

    so in config.php you’ve got

    // The number of topics that show on each page.
    $bb->page_topics = 20;

    now you can make a plugin with this, edit each page limit to your heart’s desire (anything without a $limit defined uses the config.php default)

    function custom_topic_limit($limit) {
    switch (bb_get_location()) :
    case 'front-page': $limit=45; break;
    case 'forum-page': $limit=35; break;
    case 'tag-page': break;
    case 'topic-page': break;
    case 'feed-page': break;
    case 'search-page': break;
    case 'profile-page': break;
    case 'favorites-page': break;
    case 'view-page': $limit=50; break;
    case 'stats-page': $limit=50; break;
    case 'login-page': break;
    default: $limit=20;
    endswitch;
    return $limit;
    }
    add_action( 'bb_get_option_page_topics', 'custom_topic_limit' );

    function fix_post_link ($link,$post_id) {
    remove_action( 'bb_get_option_page_topics', 'custom_topic_limit' );
    $bb_post = bb_get_post( get_post_id( $post_id ) );
    $page = get_page_number( $bb_post->post_position );
    return get_topic_link( $bb_post->topic_id, $page ) . "#post-$bb_post->post_id";
    }
    add_filter( 'get_post_link','fix_post_link',10, 2);

    The magic is in fix_post_link where it trashes whatever incorrect calculation that “get_post_link” has now done because of custom topic limits, and relculates it after unhooking the custom_topic_limit.

    No core hacks required!

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