WordPress.org

Support

Support » Themes and Templates » [Resolved] WordPress 3.4 broke my paginaton setup

[Resolved] WordPress 3.4 broke my paginaton setup

  • I updated WordPress to 3.4 on my localhost environment this morning and found it broke my pagination setup I have for a certain theme I developed.

    Basically for the index.php I have the specific pagination setup of one article per page. For archives and everything else the standard WordPress settings are used. This was working in 3.3.2 but since upgrading to 3.4 the pagination setup for the index.php was broken.

    Here is the code I’m using. I’m aware that it maybe a hackish type solution so Im open to suggestion on how to improve it/get it working in 3.4.

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('posts_per_page=1&paged=' . $paged);
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>			
    
    <!--The post -->
    
    <?php endwhile; ?>
    
    <?php else : ?>
    
    <h2>Not Found</h2>
    
    <?php endif; ?>
    ?>
Viewing 15 replies - 1 through 15 (of 23 total)
  • Moderator keesiemeijer

    @keesiemeijer

    Try it without the query_posts() and with this in your theme’s functions.php:

    function my_post_queries( $query ) {
      // not an admin page and it is the main query
      if (!is_admin() && $query->is_main_query()){
        if(is_home()){
          $query->set('posts_per_page', 1);
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    Querying Posts Without query_posts

    Thanks! That worked great, I downgraded back to 3.3.2, so I need to upgrade again and confirm. Looks promising though!

    Edit: Works well in 3.4. Thanks again!

    Moderator keesiemeijer

    @keesiemeijer

    You’re welcome. Let me know if it still works in 3.4.

    You make my day. I experienced equivalent issues and your trick solve it !

    thanks keesiemeijer, works like a charm!

    Hi guys,

    I’m using a plugin (wp-ecommerce) and it’s pagination also broke with the new WP 3.4 upgrade. I downgraded now but would like to upgrade. The code where the WP-query is:

    function wpsc_a_page_url($page=null) {
    	global $wp_query;
    	$output = '';
    	$curpage = $wp_query->query_vars['paged'];
    	if($page != '')
    		$wp_query->query_vars['paged'] = $page;
    	if($wp_query->is_single === true) {
    		$wp_query->query_vars['paged'] = $curpage;
    		return wpsc_product_url($wp_query->post->ID);
    	} else {
    		if( 1 < $wp_query->query_vars['paged']) {
    			if(get_option('permalink_structure'))
    				$output .= "paged/{$wp_query->query_vars['paged']}/";
    			else
    				$output = add_query_arg('paged', '', $output);
    
    		}
    	return $output;
    	}
    }

    There is also a function for the pagination creation but I don’t think I need to modify that. I have pasted it in pastebin though: http://pastebin.com/Ty2GtdY0

    Any ideas on how to modify it so that it works?

    Same issue with a Thematic theme. Waiting for the developers to issue a fix.

    Any chance this can modified to work with sticky posts?

    I was thinking if it would be possible to use this code to display one post per page (as is now) but if a sticky post is set, display that post on the frontpage first and then pagination every other post?

    What would be the best approach to this? Modify the function or write some conditionals in the index.php?

    Moderator keesiemeijer

    @keesiemeijer

    @jmwhite19
    Do you mean the my_post_queries function in my first post in this topic?

    It is very tricky to have one loop and stickies to adhere to the (posts_per_page) pagination rules. I made it so that if you have sticky posts their post IDs will be merged with all other post IDs.

    After they are merged the query on the home page will use the ‘post_in’ argument to display the correct (paginated) posts.
    http://codex.wordpress.org/Function_Reference/WP_Query#Post_.26_Page_Parameters

    The merged (IDs) results are created and put in the database once (when a visitor visits your home page) so WordPress doesn’t have to merge all ID’s on all paginated pages. The merged (IDs) results will be deleted if you publish or edit a post. Just visit your home page once and all the correct (merged) post id’s are back in the database

    I wouldn’t use this if your website has many posts as the array with ID’s in the database will grow very big.

    I hope that made sense.

    Here are the new functions for in your functions.php: http://pastebin.com/zDJ5nsEr

    (delete the old my_post_queries functions)

    Wow, your awesome! Your function works great. Just tested it out. Sticky post stays on top and all other posts paginate to one each page correctly.

    I cannot thank you enough! Hopefully your code can help others as well as me. I know the previous function for just limiting to one post has helped several others already!

    Thanks again!

    Moderator keesiemeijer

    @keesiemeijer

    You’re welcome. But if you have a site with more than 5000 posts I wouldn’t use this second solution because it doesn’t scale well. But then again I don’t know a better solution to have sticky posts adhere to paginagion.

    I have the same problem.

    After I have added this code to theme functions

    function my_post_queries( $query ) {
      // not an admin page and it is the main query
      if (!is_admin() && $query->is_main_query()){
        if(is_home()){
          $query->set('posts_per_page', 1);
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    the pagination of the home/blog posts works correctly, but search, category and tags pagination is still does not work after a certain number of pages, what can I do ?

    Hi, please i use wordpress 3.4, and i was playing around in the header.php

    the domain name is http://www.waohnaija.com, i was playing around with some new backgrounds, and it was working very well, until i decided to remove an ad code i had put before, i dont know what i did to spoil everything

    Moderator keesiemeijer

    @keesiemeijer

    @evo_x @ifeanyig @adnanoner
    Please create your own topics.

    Thank you, keesiemeijer! This fixed my page issues as well!

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘[Resolved] WordPress 3.4 broke my paginaton setup’ is closed to new replies.
Skip to toolbar