WordPress.org

Ready to get started?Download WordPress

Forums

Football Pool
[resolved] How Do I Paginate The Rankings? (15 posts)

  1. ephi4real
    Member
    Posted 11 months ago #

    Hi Antoine,
    Thanks for the great plugin. I have 2 questions:

    I would like to paginate the rankings to show about 80 or 100 entries per page. How can I achieve this?
    Right now I have about 400 entries showing on the ranking page and I don't want to restrict the number of rankings that are displayed.

    My second problem is that I would like to show the all the predictions for a particular match on one page, with pagination enabled. This is because my Prediction Form is shown on a Per match basis and I would like users to see what other users have predicted once predictions have closed.

    Thanks for your help.

    http://wordpress.org/plugins/football-pool/

  2. AntoineH
    Member
    Plugin Author

    Posted 11 months ago #

    There is no built in support for this in the plugin, so it would require some programming on your side.

    The ranking page uses the print_pool_ranking function in the Football_Pool_Pool class. If you extend this function with a $page parameter you can restrict the users that are displayed: start with user at position ( ( $page - 1 ) * $pagesize ).

    This is not an optimal approach, because the function still retrieves the complete ranking from the database, but I don't think this will be a problem (data sets are not that large). If you also want to optimize, then pass the $page parameter on to the get_pool_ranking function which 'feeds' the print_pool_ranking and rewrite the SQL with a LIMIT.

    Same goes for the predictions per match (show_predictions_for_match in Football_Pool_Statistics class), you can alter the SQL function with a LIMIT and pass the $page as a parameter.

  3. ephi4real
    Member
    Posted 11 months ago #

    Okay, thanks. I'll try it out. It would be really great if you added this feature to the next version.

  4. latinosamorir
    Member
    Posted 2 months ago #

    Hi,

    Did you ever work on this? If so, could you share your code please?

  5. AntoineH
    Member
    Plugin Author

    Posted 2 months ago #

    The help page has an example for the pagination code that you can use in the functions.php file of your theme or in an own plugin.

  6. latinosamorir
    Member
    Posted 2 months ago #

    Thanks. I took a look and put that in my funcions.php but nothing happens.

    After digging in, I saw that version 2.3.8 had the filters set, but version 2.4.2 lost the filters.

    Should I be calling a different filter tag?

    Which one?

    Thanks!

  7. AntoineH
    Member
    Plugin Author

    Posted 2 months ago #

    You can use the footballpool_ranking_page_html filter in the new version. I will update the example in the help file.

  8. latinosamorir
    Member
    Posted 2 months ago #

    Any chance you have the example? I haven't been able to figure it out.

    Thanks!

  9. AntoineH
    Member
    Plugin Author

    Posted 2 months ago #

    <?php
    // add a simple pagination to the ranking page
    add_filter( 'footballpool_ranking_array', 'fp_pagination' );
    add_filter( 'footballpool_ranking_page_html', 'fp_pagination_html', null, 2 );
    // and, with the same functions, add a simple pagination to the statistics page (view=matchpredictions)
    add_filter( 'footballpool_statistics_matchpredictions', 'fp_pagination' );
    add_filter( 'footballpool_statistics_matchpredictions_html', 'fp_pagination_html', null, 2 ); 
    
    function fp_pagination( $items ) {
        $pagination = new Football_Pool_Pagination( count( $items ) );
        $pagination->page_param = 'fp_page';
        $pagination->set_page_size( 10 );
        $offset = ( ( $pagination->current_page - 1 ) * $pagination->get_page_size() );
        $length = $pagination->get_page_size();
        return array_slice( $items, $offset, $length );
    } 
    
    function fp_pagination_html( $html, $items ) {
        $pagination = new Football_Pool_Pagination( count( $items ), true );
        $pagination->page_param = 'fp_page';
        $pagination->set_page_size( 10 );
        return $html . $pagination->show( 'return' );
    }
    ?>
  10. latinosamorir
    Member
    Posted 2 months ago #

    Thanks but unfortunately that did not work.

    See screenshot:

    http://imgur.com/Y240T03

    The pagination shows but the following pages don't work.

    Any idea?

  11. AntoineH
    Member
    Plugin Author

    Posted 2 months ago #

    It says '0 items'. Strange.
    I use the same code in my install and it works as expected. What version of the plugin do you use?

  12. latinosamorir
    Member
    Posted 2 months ago #

    The latest - 2.4.2

  13. sillery4ever
    Member
    Posted 2 months ago #

    same bug for me.... the page display 10 user but in the slector in bottom of page is displayed : 1 page /0 and can not go to next page !

  14. AntoineH
    Member
    Plugin Author

    Posted 2 months ago #

    I found the problem. Something I already fixed in my dev install, that's why it worked on my laptop.
    Change line 89 of file pages/class-football-pool-ranking-page.php to:

    return apply_filters( 'footballpool_ranking_page_html', $output, $ranking );

  15. ouazzanimo
    Member
    Posted 2 weeks ago #

    Hi,

    is that example for the pagination code is only available for the ranking page ? what about the ranking shortcode ?

    @sillery4ever : i notice that u did'nt use the example code in your web site (joli travail), isn't working ?

    Thanks ?

Reply

You must log in to post.

About this Plugin

About this Topic