• Resolved pglock

    (@pglock)


    I’m using your plugin “Football Pool Pagination” to make pages of matches easier to navigate. It works well on the /pool page but makes no difference to the number of matches shown on /user, it just adds the page controls to the bottom of the page.

    see https://www.dropbox.com/s/5k2h2mt8m3htbk9/player_predictions___Coinseige.png?dl=0 for example. I have pagination set to 21 items but it doesn’t break the page on /user

    Looking at the code, I think the two lines that are supposed to add pagination to /user are:

    add_filter( 'footballpool_filtered_matches', array( __CLASS__, 'fp_pagination' ) );
    add_filter( 'footballpool_user_page_html', array( __CLASS__, 'fp_pagination_html' ), null, 2 );

    When I look at class-football-pool-user-page.php I can’t see a filter for footballpool_filtered_matches. Does the code need modifying or am I missing something?

    • This topic was modified 6 years, 12 months ago by pglock.
    • This topic was modified 6 years, 12 months ago by pglock.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author AntoineH

    (@antoineh)

    You’ll have to filter the matches data set on the /user page. When I look at the class file, I think you’ll need footballpool_user_page_matches, but I didn’t test.

    Thread Starter pglock

    (@pglock)

    Thank you for that Antoine, working perfectly now.

    In case anyone else is looking for the same code, here’s my version:

    /**
     * Plugin Name: Football Pool Pagination
     * Description: Adds pagination to the matches screens and ranking page.
     * Version: 1.0
     * Author: Antoine Hurkmans
     * Author URI: mailto:[email protected]
     * License: MIT
     */
    
    class FootballPoolPagination {	
    	private static $page_size = 21; // change this if you want to alter the number of items per page. Set for 1 week of matches
    	
    	public static function init_extension() {
    		if ( ! is_admin() ) {
    			// add a simple pagination to the ranking page
    			add_filter( 'footballpool_print_ranking_ranking', array( __CLASS__, 'fp_pagination' ) );
    			add_filter( 'footballpool_ranking_page_html', array( __CLASS__, 'fp_pagination_html' ), null, 2 );
    			// and, with the same functions, add a simple pagination to the matches page and prediction page
    			add_filter( 'footballpool_user_page_matches', array( __CLASS__, 'fp_pagination' ) );
    			add_filter( 'footballpool_user_page_html', array( __CLASS__, 'fp_pagination_html' ), null, 2 );
    			add_filter( 'footballpool_page_pool_matches_filter', array( __CLASS__, 'fp_pagination' ) );
    			add_filter( 'footballpool_pool_page_html', array( __CLASS__, 'fp_pagination_html' ), null, 2 );
    		}
    	}
    	
    	public static function fp_pagination( $items ) {
    		$pagination = new Football_Pool_Pagination( count( $items ) );
    		$pagination->page_param = 'fp_page';
    		$pagination->set_page_size( self::$page_size );
    		$offset = ( ( $pagination->current_page - 1 ) * $pagination->get_page_size() );
    		$length = $pagination->get_page_size();
    		return array_slice( $items, $offset, $length );
    	}
    	
    	public static function fp_pagination_html( $html, $items ) {
    		$pagination = new Football_Pool_Pagination( count( $items ), true );
    		$pagination->page_param = 'fp_page';
    		$pagination->set_page_size( self::$page_size );
    		return $html . $pagination->show( 'return' );
    	}
    }
    
    add_filter( 'plugins_loaded', array( 'FootballPoolPagination', 'init_extension' ) );

    Hi AntoineH,
    unfortunately the “Football Pool Pagination” plugin goes into conflict with “Football Pool Only Open Matches”. if they are both active, all the contents of the POOL page will disappear.

    thanks a lot!

    Plugin Author AntoineH

    (@antoineh)

    Hi,

    Could be as simple as setting the correct priority. Both filter the matches collection, so I think the pagination – in your case – filtered the collection to the first page and if that page only contains closed matches, then these are filtered out with the other extension. Resulting in no matches to show for the first page.

    Can you try to lower the priority of the pagination, so that extension is executed last? You can do so by added a priority value as the third parameter to all the lines that call the fp_pagination method, e.g.

    // The number 90 is the value for priority, higher numbers correspond with later execution (default is 10)
    add_filter( 'footballpool_print_ranking_ranking', array( __CLASS__, 'fp_pagination' ),  90 );
    

    p.s. Next time please open a new topic in the forum. Your question is not really related to this topic and opening a new topic will help other users with the same problem finding a solution easier.

    p.s.2 I will update the standard code for pagination with a lower priority. Think that will work better for most situations.

    • This reply was modified 6 years, 11 months ago by AntoineH.

    unfortunately it does not seem to work even with the change you proposed to me.
    can you check if the code is correct? I do not know PHP

    
    <?php
    /**
     * Plugin Name: Football Pool Pagination
     * Description: Adds pagination to the matches screens and ranking page.
     * Version: 1.0
     * Author: Antoine Hurkmans
     * Author URI: mailto:[email protected]
     * License: MIT
     */
    
    // Save this plugin in the wp-content/plugins folder and activate it //
    
    class FootballPoolPagination {	
    	private static $page_size = 21; // change this if you want to alter the number of items per page. Set for 1 week of matches
    	
    	public static function init_extension() {
    		if ( ! is_admin() ) {
    			// add a simple pagination to the ranking page
    
    /*			add_filter( 'footballpool_print_ranking_ranking', array( __CLASS__, 'fp_pagination' ) );     */
                            add_filter( 'footballpool_print_ranking_ranking', array( __CLASS__, 'fp_pagination' ),  90 );
    
    			add_filter( 'footballpool_ranking_page_html', array( __CLASS__, 'fp_pagination_html' ), null, 2 );
    
    			// and, with the same functions, add a simple pagination to the matches page and prediction page
    /*			add_filter( 'footballpool_user_page_matches', array( __CLASS__, 'fp_pagination' ) );      */
    			add_filter( 'footballpool_user_page_matches', array( __CLASS__, 'fp_pagination' ), 90 );
    
    			add_filter( 'footballpool_user_page_html', array( __CLASS__, 'fp_pagination_html' ), null, 2 );
    
    /*			add_filter( 'footballpool_page_pool_matches_filter', array( __CLASS__, 'fp_pagination' ) );     */
    			add_filter( 'footballpool_page_pool_matches_filter', array( __CLASS__, 'fp_pagination' ), 90 );
    
    			add_filter( 'footballpool_pool_page_html', array( __CLASS__, 'fp_pagination_html' ), null, 2 );
    		}
    	}
    	
    
    	public static function fp_pagination( $items ) {
    		$pagination = new Football_Pool_Pagination( count( $items ) );
    		$pagination->page_param = 'fp_page';
    		$pagination->set_page_size( self::$page_size );
    		$offset = ( ( $pagination->current_page - 1 ) * $pagination->get_page_size() );
    		$length = $pagination->get_page_size();
    		return array_slice( $items, $offset, $length );
    	}
    	
    	public static function fp_pagination_html( $html, $items ) {
    		$pagination = new Football_Pool_Pagination( count( $items ), true );
    		$pagination->page_param = 'fp_page';
    		$pagination->set_page_size( self::$page_size );
    		return $html . $pagination->show( 'return' );
    	}
    }
    
    add_filter( 'plugins_loaded', array( 'FootballPoolPagination', 'init_extension' ) );
    

    if you agree, as soon as the problem is solved, I create a new topic where I will reply my question.
    I’m sorry for the inconvenience

    Plugin Author AntoineH

    (@antoineh)

    @psike64’s problem can be solved by changing the filter footballpool_page_pool_matches_filter to footballpool_predictionform_matches_filter.

    • This reply was modified 6 years, 10 months ago by AntoineH.

    thanks a lot, it works ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Pagination on /user page’ is closed to new replies.