• Hi all,

    Here I am again, cap in hand, looking for your help!

    I’m setting up a site for an art gallery and have set up a category for each artist that the gallery stocks. Every art work, as well as being posted to its’ artist category, is also tagged appropriately as “Original”, “Print”, or “Sculpture”.

    When clicking on any given tag the site returns all pages with that tag – as you would expect – in reverse chronological order. I was wondering if it would be possible to return the tag list sorted by artist as follows:

    Originals
    ArtistA
    Painting1
    Painting2
    Painting3

    ArtistB
    Painting1
    Painting2
    Painting3

    so on and so forth.

    Does anyone have any idea how I could achieve this?

    Many thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • This seems to work:

    <?php
    $tags = get_tags();
    $categories=get_categories('orderby=name&order=ASC');
    foreach ($tags as $tag) {
      if ($tag->count > 0) {
        echo 'Tag: <a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a>
     ';
        foreach ($categories as $category) {
          $posts=get_posts('showposts=-1&cat='. $category->term_id .'&tag='.$tag->name .'+'. $tag->name);
          if ($posts) {
            echo 'Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>
     ';
            foreach ($posts as $post) {
              setup_postdata($post); ?>
              <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    
              <?php
            } // foreach ($posts
          } // if ($posts
        } // foreach ($categories
      } // if ($tag->count
    } // foreach ($tags
    ?>

    [edit moved get_categories. Note this of course ignores posts with NO tags]

    Thread Starter exbionic

    (@exbionic)

    Hi Michael,

    Thanks for your reply. I’ll give that a go and see what happens.

    Many thanks again for your help and posting the code.

    Best wishes,

    Scott.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Tag list sorted by category’ is closed to new replies.