Viewing 8 replies - 1 through 8 (of 8 total)
  • <?php
    //if viewing specific tag archive, 'grade-1' or 'grade-2', then display 5 post titles from that tag
    if ( is_tag(array('grade-1','grade-2')) ) {
      $qtag = get_query_var('tag');
      $tag = get_term_by('name',$qtag, 'post_tag');
      $taxonomy = 'post_tag';//  e.g. post_tag, category, custom taxonomy
      $param_type = 'tag__in'; //  e.g. tag__in, category__in, but genre__in will NOT work
      $args=array(
        "$param_type" => array($tag->term_id),
        'post_type' => 'post',
        'showposts'=>5,
        'caller_get_posts'=>1
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
      echo '<h2>Recent Posts</h2>';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
          <?php $found_none = '';
        endwhile;
      }
    }
    wp_reset_query(); // to use the original query again
    ?>
    Thread Starter acornrevolution

    (@acornrevolution)

    I tried this script out. it doesn’t return any errors, but it also doesn’t print anything in my sidebar. Here is the page I am using it at:
    http://www.anthonyteacher.com/tag/grade-2/. The recent posts should appear above Blogroll, but I get nothing. I even modified the code to print a small message if no posts are found, and still got nothing. What could be wrong?

    Get Otto’s PHP Code Widget and and put the code in that.

    Thread Starter acornrevolution

    (@acornrevolution)

    It’s already in my sidebar.php. What will the widget do differently? I’ll try it anyway.

    if you have a dynamic sidebar, make sure you have your code in an area that is displayed despite widgets.

    Thread Starter acornrevolution

    (@acornrevolution)

    I have this between other snippets of PHP code, everything else works fine. But this still is not working. It’s just not doing anything. I’d still like some help on this if possible.

    Thread Starter acornrevolution

    (@acornrevolution)

    MichaelH,
    I tried your other code, listed here: http://wordpress.org/support/topic/337112?replies=14, which worked, but the current code I still can’t get to work. I’ve tried modifying both, but still can’t seem to get it.

    Thread Starter acornrevolution

    (@acornrevolution)

    I have a custom taxonomy where a tagged post is not located at .com/tags/post-title but .com/class/post-title. Does that make a difference?

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘List Recent Posts by Tag?’ is closed to new replies.