it works everywhere on my site but it isnt working in category.php. When i click page to it goes to... domain.com/category/cat-slug/page/2

by the way this is showing custom post types within certain categories (no actual plain 'posts')

But when the page loads its just the 404 page?

When i go to /page/1 it works fine, just not for any other pages.

In permalinks I have /%postname%/ although I have set category base to 'category' just to be safe.

I also know this is kind of a convoluted way of doing it but i wasnt sure a better way.


get_header(); ?>

<div class="home-gradient">
<div id="container">
<div class="content-wrap">  


   $catID = get_query_var('cat');
   $catName = strtolower(get_cat_name($catID));

    if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
  } elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
  } else {
    $paged = 1;

  $myquery = new WP_Query(array(
        'post_type' => 'any',
            'paged' => $paged,
            'posts_per_page' => 1,
      'category_name' => $catName)

        while ( $myquery->have_posts() ) : $myquery->the_post(); 

        $img_id = get_post_meta($post->ID,'main_image',true);
        $img_url = wp_get_attachment_url($img_id);

blah blah code here for output


   wp_pagenavi( array( 'query' => $myquery ) );
  • Why do you do conditional check for get_query_var( 'paged' )?
    – Mamaduka
    Mar 25, 2012 at 10:45
  • I looked around forever for a fix to make pagination work and that's the only thing that worked. I'm not too worried about more efficient ways to do things at this point, i just want to get it working :(
    – Tallboy
    Mar 25, 2012 at 15:20

1 Answer 1

$catname = wp_title('', false);
$wp_query = new WP_Query();

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php the_title(); ?>
<?php } ?>

<?php endwhile; ?>

<?php next_posts_link('&laquo; Older Entries') ?>
<?php previous_posts_link('Newer Entries &raquo;') ?>

I think that you need to look at the $paged variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.