Saturday, 1 June 2013

Paginate tags page

Paginate tags page

If I click a random tag I want the tag page to list only 20 posts that is related to that tag and paginate it.
<?php
/**
 * The template for displaying Tag Archive pages.
 */

get_header(); ?>

        <div id="container">
            <div id="content" role="main">

                <h1 class="page-title"><?php
                    printf( __( 'Tag Archives: %s', 'twentyten' ), '<span>' . single_tag_title( '', false ) . '</span>' );
                ?></h1>

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'post', 'posts_per_page' => 20, 'paged' => $paged );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); ?>

        <div <?php post_class() ?>>
                <ul><li id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_post_thumbnail(thumbnail); ?></a></ul>

            </div>

        <?php endwhile; ?>
      <?php if (function_exists("pagination")) {
    pagination($additional_loop->max_num_pages);
} ?>


            </div><!-- #content -->

<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
The problem with this code is it's listing all the posts and not posts that are related to that tag. Can anyone help me fix?

No comments:

Post a Comment