ThemeShaper Forums » Thematic


Create post list grouped by tag

(3 posts)
  • Started 11 years ago by bronwyn
  • Latest reply from bronwyn
  • This topic is resolved
  1. bronwyn

    I am trying to make a custom loop to do this:

    Tag Name 1
    post 1
    post 2
    Tag Name 2
    post A
    post B

    For each tag, I want to have a tag name header (linked to the tag archive page) and then two posts.

    I have been trying to use this code:

    $taglist = get_terms('post_tag', 'hierarchical=0&orderby=name&hide_empty=1'); foreach ($taglist as $pftag) {
    <h3><?php print_r($pftag->name); ?></h3>
    <?php while (have_posts()) : the_post();
    endwhile; }

    The posts returned by query_posts are not filtered by tag at all. It just pops up the most recent 2 posts over and over. What am I doing wrong, and why is this so %$#^ing hard? I've been working on this for about 4 hours with very little progress, even though I got the categories version of this working much faster.

    The print_r for the tag name header is messy, but I haven't found anything else that actually outputs the tag name for *all* entries...

    Posted 11 years ago #
  2. bronwyn

    The problem is solved thanks to the kindness of alchymyth over on the Wordpress forums. In case anyone else wants to know how it is done, it goes like this:

    // get the tag list
    $taglist = get_terms('post_tag', 'hierarchical=0&orderby=name&hide_empty=1');
    // iterate through the tag list
    foreach ($taglist as $pftag)
    //get 2 posts belonging to the tag -- ONLY the slug works to filter by tag
    // make a linked heading with the tag name
    <h3>slug); ?>"><?php echo($pftag->name); ?></h3>
    // make the actual loop for the posts, which outputs them using a custom action, because I use this format many places
    <?php while (have_posts()) : the_post();

    Posted 11 years ago #
  3. bronwyn

    Please disregard previous post; the code got broken during pasting.

    Code that actually works is posted over at

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.