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.

I have

index.php
archive.php
...

When I go to domain.com, it loads index.php, which is expected.

But, when I go www.domain.com/page/2/, it loads the correct posts (as in, the posts in the second page), but uses in index.php template. I want to load the archive.php template. How is this achievable?

share|improve this question
add comment

2 Answers 2

archive.php is not used for subsequent pages of non-search, non-taxonomy, ... based subsets of content.

I think you might be looking for paged.php (but that'll also be used for the first page).

Alternatively add logic to index.php to call a different template where page number is greater than one.

Correction on reviewing http://codex.wordpress.org/Template_Hierarchy#Visual_Overview pages.php is not the answer. Paged (ie. not single) posts use home.php otherwise index.php only.

So you'll need to put in your own logic (presumably to home.php) to use index.php or some custom template for posts.

(This answer shows the WP logic to decide which template to use.)

share|improve this answer
    
Yes thanks that's what I eded up doing. I just used if .. else –  21zna9 Jul 18 '12 at 21:47
add comment

Here's how you would do this, as it is not a native feature of WP.

Basically, check if $paged is set, which you can do by calling is_paged() inside a conditional.

<?php if ( ! is_paged() ) : 
// code for home page 
else: 
// code for archive page
endif; 
?> 

Making use of templates can make this index.php still look tidy/neat.

You're going to need to make sure you're doing this, though:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?> 

Before either the home query or the archive query.

share|improve this answer
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.