• I am trying to find a way to create a list (not cloud) of tags and to have second level lists of links to all the posts related to each tag — essentially the same list that would result if you had clicked on the tag-link.

    So, say I had two tags, “cake” and “candy” and there were several recipes tagged with those links, this is the result I am looking for:

    • cake
    • candy

    So I start with this:

    <?php
    if(get_the_tag_list()) {
    get_the_tag_list(‘

    • ‘,’
    • ‘,’

    ‘);
    }
    ?>

    and I get the list of tags. But how do I get the sublist of related posts? Probably this has been answered already, but I can’t seem to locate it.

    thanks for looking

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here’s an example you might consider:

    <?php
    //get all terms (e.g. categories or post tags), then display all posts in each term
    $taxonomy = 'post_tag';//  e.g. post_tag, category
    $param_type = 'tag__in'; //  e.g. tag__in, category__in
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC'
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts in '.$taxonomy .' '.$term->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        }
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter Jake Sterling

    (@jake-sterling)

    Thanks, I’ll try that. Sorry about my code example! I didn’t see that there was a code button.

    Jake

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List of posts from a tag’ is closed to new replies.