WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination hell, please help (5 posts)

  1. jennybeaumont
    Member
    Posted 1 year ago #

    Hi Folks,

    Am tearing my hair out, hope someone can see what I cannot. After much research, I've compiled the following snippets in order to paginate both my category pages (standard loop) and my blog home home page, which runs on a custom WP_query (because I only want to show 2 posts at a time vs. the 9 defined in my settings for categories).

    Pagination works fine for the categories, but for the blog page, I get stuck on page 5 > page 6 turns up a 404 not found.

    This bit of code is in my functions.php :

    function jlg_pagination($type = 'plain', $endsize = 1, $midsize = 1) {
        global $wp_query, $wp_rewrite;
        $current = get_query_var( 'paged' ) > 1 ? get_query_var('paged') : 1;
    
        // Sanitize input argument values
        if ( ! in_array( $type, array( 'plain', 'list', 'array' ) ) ) $type = 'plain';
        $endsize = absint( $endsize );
        $midsize = absint( $midsize );
    
        // Setup argument array for paginate_links()
        $pagination = array(
            'base'      => @add_query_arg( 'paged', '%#%' ),
            'format'    => '',
            'total'     => $wp_query->max_num_pages,
            'current'   => $current,
            'show_all'  => false,
            'end_size'  => $endsize,
            'mid_size'  => $midsize,
            'type'      => $type,
            'prev_text' => '<',
            'next_text' => '>'
        );
    
        if ( $wp_rewrite->using_permalinks() )
            $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ).'page/%#%/', 'paged' );
    
        if ( ! empty( $wp_query->query_vars['s'] ) )
            $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
    
        return paginate_links( $pagination );
    
    }

    and this is my custom loop (I've tried both in index.php and in a template page - same result) :

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    			$wp_query = new WP_Query ( array('showposts' => 2, 'paged' => $paged) );
    				while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

    Anyone see where the problem might be?

    many thanks,
    -jennyb

    [please allow more time to get a reply - http://codex.wordpress.org/Forum_Welcome#No_Bumping
    if it is so urgent, consider to hire sombody http://jobs.wordpress.net/ ]

  2. Peter_L
    Member
    Posted 1 year ago #

    That's a bit too complex for me but did your page 5 have 1 or 2 posts in it?

  3. jennybeaumont
    Member
    Posted 1 year ago #

    Hi Peter,

    It had 2. I've tried increasing the default number of posts per page, but that doesn't help :(

    thnx,
    -jennyb

  4. jennybeaumont
    Member
    Posted 1 year ago #

    I should probably add that this custom query is actually on index.php. Is that a problem?

  5. jennybeaumont
    Member
    Posted 1 year ago #

    It was my settings :-/
    Used a page template and turned off the Read settings on the Latest posts page to bypass the index. Voilà, ça marche !

Topic Closed

This topic has been closed to new replies.

About this Topic