Search code examples
phpcategoriesjquery-post

Joining two query_posts codes


How do I join these two codes so that they work?

<?php query_posts( array(
  'posts_per_page' => 16,
  'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ), ));
?>

and

<?php query_posts('category_name=' . $category->cat_name . '&paged='. get_query_var('paged')); ?>

The first one has working navigation (when I click older/newer posts) and the second one doesn't (it returns the same page with the correct URL). I had that problem with my other template so I used the code posted above to get the navigation to work. Also, the first code shows 16 posts and the second one only 5.

I tried combining them by just adding those two lines to the second code but it either gives me an error, gives me a non-working navigation or it simply gives the 16 posts but not displayed by the category.


Solution

  • try:

    <?php 
      query_posts( 
        array(
          'posts_per_page' => 16,
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ), 
          'category_name' => $category->cat_name
        )
      );
    ?>