Support » Plugins » show posts list in tag view, code not work

  • Resolved lzp729

    (@lzp729)


    Hi all, i am now trying to display the posts list by tag in the tag view, i wrote some code in the widget(support php), but my code don’t work, is there any solution? below is my codes.

    <ul>
    <?php
    $lastposts = get_posts('numberposts=100$tag='.single_tag_title().'\'');
    foreach($lastposts as $post) :
    ?>
      <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
      </li>
    <?php endforeach; ?>
    </ul>

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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>";
    Thread Starter lzp729

    (@lzp729)

    thank you, you are great

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘show posts list in tag view, code not work’ is closed to new replies.