I have my blog page limited to 5 posts on the main page, which I'm happy with. However, I want my tag pages to list much more, maybe 15 or so. How do I most easily make this change? There's no option on the reading page.



I would put this in functions.php:

function main_query_mods( $query ) {
    // check http://codex.wordpress.org/Conditional_Tags to play with other queries
    if(!$query->is_main_query()) {
    if(is_tag()) {
add_action( 'pre_get_posts', 'main_query_mods' );
| improve this answer | |

There are so many ways you can actually go about this and here's ONE...

Create a file called tag.php and insert the following into it;

<?php get_header();?>

<?php $tag_loop = new WP_Query( array( 'orderby' => 'DESC', 'posts_per_page' => 15) ); ?>
<?php while ( $tag_loop->have_posts() ) : $tag_loop->the_post(); ?>

    <div <?php post_class() ?>>

            <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

            <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>

            <div class="entry">
                <?php the_excerpt(); ?>


<?php endwhile;?>

<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

<?php get_sidebar();?>
<?php get_footer();?>

Save this file and place it into your theme directory along with your other template files.

What will happen in this instance is that WordPress will check for the existance of tag.php first and if it finds a template file matching that name it will then dislpay your custom loop. If not it will move onto your archive.php file.

Now like I said this is one way to achieve this, you can do all sorts of trickery and conditional wizardy in files that don't neccessarily have to be tag.php however for simplicity this option is the easiest.

Further more it will give you a good idea of what WordPress checks for in order of existance;


  • tag-slug.php
  • tag-id.php
  • tag.php
  • archive.php
  • index.php

So in this case your tag.php will take precedence over your archive.php file and if you ever wanted to target a specific tag you could then create a template based on ID or Slug. This gives you a greater level of control over how you display all of your content.

Really no limitations!

| improve this answer | |
  • Now you get the regular query and a custom one. Doesn't look very efficient. ;) – fuxia Apr 14 '12 at 10:13
  • @toscho Please elaborate as to what you mean by "doesn't look very efficient" ? Curious to know... – Adam Apr 14 '12 at 10:39
  • 1
    When tag.php is called the regular tag query is already done. Now you create a second query. So you end up with one wasted query. It is faster (more efficient) just to change the main query like @offroff does it. – fuxia Apr 14 '12 at 12:07

You should be able to hook in right before the query is done using something like pre_get_posts and do something like this (conditionally, of course):

global $wp_query;
$wp_query->set( 'posts_per_page', 15 );

If you wanted an even better solution, you could add a setting to the backend where you can easily change that value without having to go into code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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