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.php lists articles on the first page, and on the bottom I have a pager.

When I click page 2, the index.php page is loaded and the url looks like this: http:// www.mysite.com/some-category/page/2.

Why isn't category.php page loaded when URL has /page/2/ ?

My permalink structure looks like this: /%category%/%postname%/

If it helps to see the code, here it is:

<?php
/**
 * Template Name: Article List - Category
 *
 * Displays articles from magazine
 *
 * @package WordPress
 * @subpackage Norwegian_Fashion
 * @since Norwegian Fashion 1.0
 */

  get_header(); 

  // Get current page. Is used for pagination.
  $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

?>
  <div id="mainArea">
    <div id="articleList">
      <ul>
        <?php while (have_posts()) : the_post(); ?>
          <li>
            <div class="photo">
                <a href="<?php the_permalink(); ?>"> <?php the_related_image_scaled('h=180') ?> </a>
            </div>

            <div class="info">
              <span class="date"><?php the_date(); ?></span> | by <span class="byline"><?php the_custom_author(); ?></span>
              <header> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1></header> 
              <div class="intro"><?php the_intro('num_words=25'); ?></div>
              <div id="post_metadata">  
                <div class="keywords"> <?php the_tags('Keywords: ', ','); ?> </div>
              </div>
              <div class="commentsCount"><?php comments_number('no comments','1 comment','% comments'); ?></div>       
            </div>      
          </li>
        <?php endwhile; ?>
      </ul>
      <?php  
        if(function_exists('wp_pagenavi')) 
        { wp_pagenavi(); } ?>
    </div>
  </div>

  <aside>
    <div id="sidebar">
      <ul>  
        <?php //dynamic_sidebar( 'frontpage' ); ?>
      </ul>  
    </div>
  </aside>
  <?php get_footer(); ?>
share|improve this question
    
we'd probably need to see the code from the whole file. That url looks right to me for getting you page 2 so I figure something else must be screwing it up. Paste the code into your question please. –  curtismchale Nov 11 '10 at 15:17
    
Does the page work correctly if you use one of the provided permalink structures? –  t31os Nov 11 '10 at 15:42
    
@curtismchale - code added –  Steven Nov 11 '10 at 16:11
2  
Are you using a category base in permalinks? If not, using one would probably solve this. –  hakre Nov 12 '10 at 0:47
    
@hakre: I have written in my question, my permalink setup. –  Steven Nov 12 '10 at 9:13
show 3 more comments

3 Answers

Correct me if I'm wrong.

I guess you use that code to custom display a category.

If that's the case, right before this code:

<?php while (have_posts()) : the_post(); ?>

You will need to add query_posts():

<?php query_posts('cat={categoryID}&paged=' . $page); ?>
share|improve this answer
    
If category.php has been loaded as the template file, it means is_category() should return true, and this implies the search is already limited to the given category. –  Jan Fabry Nov 12 '10 at 7:12
    
As Jan points out, /some-category/ is a category. The category will always be in the URL. –  Steven Nov 12 '10 at 9:09
    
since this is the category template, I'm guessing that WP "see's" that /category-name/ is a category and thus I do not have to figure out what cat ID it is. Henche I should not need to use query_posts. –  Steven Nov 21 '10 at 15:58
add comment
up vote 1 down vote accepted

I found he answer.

The problem was that my URL looked like this: www.mysite.com/wp-category/.
This was wrong.

The right way was this: www.mysite.com/category/wp-category/.
Now it works.

I thought that since I was using the following permalink: /%category%/%postname%/, did not need the extra /category/ in my URL. But now I know.

share|improve this answer
add comment

I think there is actually an issue with your loop. Try using this one below (with the content setup as you need).

<?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

        <?php // Individual Post Styling ?>

    <?php endwhile; ?>

        <?php // paged navigation - next post, previous post... ?>

    <?php else : ?>

    <h3>Ooops looks like there was an issue. Please <a href="<?php echo get_option('home'); ?>/contact" title="Contact Us">get in touch</a> with us and we'll get the problem fixed.</h3>

<?php endif; ?>
share|improve this answer
    
This did not help. The reson is that when I click 2 in page list, Wordpress does not recognize that it is a category page, tehrefore it loads the frontpage, but with some weird styling. You can see it in action here: norwegianfashion.no/fashion-report –  Steven Nov 12 '10 at 9:12
    
As hakre suggested, add a category base to your permalink structure. –  t31os Nov 14 '10 at 14:55
add comment

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.