• Vince

    (@vincentrich)


    <?php
    			#RETRIEVE CATEGORY ID
    			$category_id = get_cat_id(single_cat_title("", false));
    
    			#RETRIEVE PAGE
    			$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    			#RETRIEVE PRODUCTS
    			query_posts('cat=$category_id&paged=$page&posts_per_page=10');
    
    			#DISPLAY PRODUCTS
    			while(have_posts())
    			{
    				the_post();
    				?>
    
    			<?php
    			}
    			?>

    This is my code. I found the fix on this forum and added it to my code. However, it still does not work in my blog. I still see similar posts on page 1 and 2.

    I am trying to display posts from 1 category only.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Vince

    (@vincentrich)

    <?php
    			#RETRIEVE CATEGORY ID
    			$category_id = get_cat_id(single_cat_title("", false));
    
    			#RETRIEVE PAGE
    			$page = (get_query_var('paged')) ? get_query_var('paged') : 1;			
    
    			#RETRIEVE PRODUCTS
    			$products = new WP_Query("cat=$category_id&showposts=10&paged=$page");
    
    			#DISPLAY PRODUCTS
    			while($products->have_posts())
    			{
    				$products->the_post();

    I found a solution. Use WP_Query instead!

    You didn’t have to use WP_Query.
    What you had in your first example was almost perfect.

    The problem was that you need to use double quotes instead of single quotes when passing variables to the query_posts() function.

    <?php
    #RETRIEVE CATEGORY ID
    $category_id = get_cat_id(single_cat_title("", false));
    
    #RETRIEVE PAGE
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    #RETRIEVE PRODUCTS
    query_posts("cat=$category_id&paged=$page&posts_per_page=10");
    
    #DISPLAY PRODUCTS
    while(have_posts()) {
    	the_post();
    ?>
    <?php
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts Pagination Fix Does Not Work For Me…’ is closed to new replies.