i am now trying to display the posts list by tag in the tag view
Are you talking about a Tag Archive? If so see Tag Template as you may not need any code to display posts — just let your archive.php handle that.
But here’s something you might used, again if view a tag archive.
<?php
if ( is_tag() ) {
$tag = get_query_var('tag');
$args=array(
'showposts'=>100,
'tag' => $tag
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
?>
Thread Starter
lzp729
(@lzp729)
great MichaelH, thank you sooooooooo much, what you share is just what i need, thank you
Thread Starter
lzp729
(@lzp729)
i made some change to your sample, and it works perfect for me now
<?php
if ( is_tag() ) {
$tag = get_query_var('tag');
$args=array(
'showposts'=>100,
'tag' => $tag
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {?>
<li class="widget widget_recent_entries" id="<?php echo $tag;?>-posts">
<h2 class="widgettitle"><?php echo single_tag_title(); ?></h2>
<ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile;
}?>
</ul>
<?php }?>
another thing is, what should i see if i am going to do the same thing for the monthly archive?
Thread Starter
lzp729
(@lzp729)
MichaelH, would you please give me a list of query vars list i can get from get_query_var()
I put this in a template to see that:
echo "<pre>"; print_r($wp_query->query_vars); echo "</pre>";