Skip to:
Content
Pages
Categories
Search
Top
Bottom

here’s how to add front page pagination (page numbers)


  • _ck_
    Participant

    @_ck_

    update: I’ve now included this functionality in the topics-per-page plugin so use that instead which is maintained and not this mini-plugin which will not work properly with 1.0a

    Here’s something I had made a mental note of quite awhile ago but forgot to do, add pagination to the front-page for the latest discussions. You can see a demo near the bottom of http://bbshowcase.org/forums/

    (the following two functions are included in the 0.0.4 version of topics-page-page plugin, so don’t use them if you have that)

    add_filter('get_latest_topics_limit','front_page_pagination',999);
    function front_page_pagination($limit="") {
    global $page;
    if (is_front() && $page>1) {$limit.=" OFFSET ".($page-1)*bb_get_option('page_topics');}
    return $limit;
    }
    function front_page_pages() {
    global $page, $bbdb;
    echo get_page_number_links( $page, $bbdb->get_var("SELECT SUM(topics) FROM $bbdb->forums"));
    }

    1. add to your front-page.php template

    <div class="nav"><?php front_page_pages(); ?></div>

    AFTER

    <?php endforeach; endif; // $topics ?>
    </table>

    2. If you use rewrite slugs you MUST add the following rule to your .htaccess file

    RewriteRule ^page/([0-9]+)/?$ /forums/?page=$1 [L,QSA]

    anywhere before </IfModule>

    where /forums/ is the path to your bbpress install.

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

  • _ck_
    Participant

    @_ck_

    Also, if you’d like to dynamically add some text to the left (or even the right) of the page links without hacking all your templates, you can use this trick:

    // add "pages:" to page links
    function text_topic_pages( $text ) { if ($text) {$text="pages: ".$text;} return $text; }
    add_filter('topic_pages', 'text_topic_pages');
    add_filter('forum_pages', 'text_topic_pages');

    This way the word “pages:” appears before the page number links only if there actually are any pages for the results.


    TrishaM
    Participant

    @trisham

    Excellent tip on adding the text “Pages” – this is a great plugin and works perfectly.


    TrishaM
    Participant

    @trisham

    Hmmm found a problem but not sure if it’s related to this pagination or not….

    When I am on my Front Page and click on any of the other pages numbers (2, 3, Next>>, etc) I get this error:

    Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 0 in /[myURL]/Forum/bb-includes/template-functions.php on line 925

    Any ideas?


    TrishaM
    Participant

    @trisham

    By the way, this only happens on my front-page.php. When I use the pagination on my forum pages I don’t get the error……

    Started new topic:

    http://bbpress.org/forums/topic/topics-per-page-plugin-new-problem

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

You must be logged in to reply to this topic.