Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My category page navigation doesn't seem to be showing up at all, what am I missing in my coding?

<?php get_header(); ?>

<div class="inner-page">
  <div class="page-spacer"></div>
  <!-- Content Start -->
  <div id="content-top"></div>
  <div id="category-content-wrapper">
    <div id="category-content" role="main">
      <?php if ( have_posts() ) : ?>
      <header class="page-header">
        <div class="page-title category-title">
          <h1>
            <?php
                        printf( __( '%s', 'rsi' ), '' . single_cat_title( '', false ) . '' );
                    ?>
          </h1>
        </div>
        <?php
                        $category_description = category_description();
                        if ( ! empty( $category_description ) )
                            echo apply_filters( 'category_archive_meta', '<div class="category-archive-meta">' . $category_description . '</div>' );
                    ?>
      </header>
            <?php wp_pagenavi() ?>
      <?php /* Start the Loop */ ?>
      <?php
$args = array( 'category' => 5 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
      <div class="post-holder">
        <?php if (has_post_thumbnail( $post->ID ) ): ?>
        <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
        <a href="<?php the_permalink(); ?>">
        <div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')"> </div>
        </a>
        <?php endif; ?>
        <div class="blog-title">
          <h2><a href="<?php the_permalink(); ?>">
            <?php the_title(); ?>
            </a></h2>
        </div>

        <div class="blog-excerpt">
          <?php the_excerpt(); ?>
        </div>
                <div class="blog-date"> Posted on:
          <?php the_date(); ?>
        </div>
      </div>
      <?php endforeach; ?>
      <?php else : ?>
      <article id="post-0" class="post no-results not-found">
        <header class="entry-header">
          <h1 class="entry-title">
            <?php _e( 'Nothing Found', 'rsi' ); ?>
          </h1>
        </header>
        <!-- .entry-header -->

        <div class="entry-content">
          <p>
            <?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'rsi' ); ?>
          </p>
          <?php get_search_form(); ?>
        </div>
        <!-- .entry-content --> 
      </article>
      <!-- #post-0 -->

      <?php endif; ?>
            <?php wp_pagenavi() ?>
    </div>
    <!-- #content -->
    <div id="sidebar">
      <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Right Sidebar')) : ?>
      <?php endif; ?>
    </div>
    <div class="clear-block"></div>
  </div>
  <div class="clear-block"></div>
</div>
<div class="clear-block"></div>
<div id="content-bottom"></div>
<!-- Content End -->
</div>
<?php get_footer(); ?>
share|improve this question

3 Answers 3

up vote 1 down vote accepted

You should take a closer look at the [http://codex.wordpress.org/Template_Hierarchy Template Hierarchy]. From what I understood in your code is that you're trying to list posts in the category where ID = 5. You can easily map that to the category-slug.php or category-id.php template files, so you won't have to do any extra get_posts.

The problem with pagination is that wp_pagenavi is looking for your $wp_query global and doing pagination for the original query (which you don't filter.) Or maybe the only reason is that your WP-PageNavi plugin is not installed or disabled ;)

share|improve this answer

Are you sure you have enough posts in your category for it to display page navigation?

I have just tried your exact code on my dev site and it works fine. However I had to set this setting to see the navigation markup produced by the plugin as I didn't have tnough posts in any specific category to warrant pagination:

Always Show Page Navigation

You will find this setting just under "Page Navigation Options" about half way down the PageNavi admin page in the "Settings" area of the dashboard.

share|improve this answer

I am not sure but u can user <?php wp_reset_query(); ?> after the foreach.

<?php endforeach; ?>
<?php wp_reset_query(); ?>

May it work for you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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