• Resolved Kahil

    (@kahil)


    Ok…so…

    I would like to have an archive page where posts are listed into groups based on their tag and then sorted alphabetically.

    Roughly like…

    A post with tag1
    B post with tag1
    C post with tag1

    A post with tag2
    B post with tag2
    C post with tag2

    Any help would be greatly appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Kahil

    (@kahil)

    I’m not looking for a list of links. And that doesn’t let you group them by tags, ect.

    Thread Starter Kahil

    (@kahil)

    I know how to sort them alphabetically using a query that goes in before the loop, per the codex here…I just don’t know how to group them by their tag.

    Thread Starter Kahil

    (@kahil)

    and the only thing in the codex about sorting with tags is to do so with specific tag ids or names.

    This is sloppy, and incomplete, and may not even be a proper solution, but it may help you get started:

    <?php $tag = wp_tag_cloud('format=array' ); ?>
    <?php foreach($tag) { ?>
    	<?php wp_tag_cloud(''); ?>
        <?php if (have_posts()) : ?>
                <?php while (have_posts()) : the_post(); ?>
                    <?php if( has_tag($tag) ) { ?>
                        <h3><?php the_title(); ?></h3>
                        <?php the_content('More ?'); ?>
    				<?php } ?>
                <?php endwhile; ?>
        <?php endif; ?>
    <?php } ?>
    Thread Starter Kahil

    (@kahil)

    I will try it out and let you know. My other thought was to do something with multiple loops.

    Thread Starter Kahil

    (@kahil)

    Ok… I have managed to get close by using multiple loops. Now my problem is getting the archive to respect the category I choose. Now it is showing all posts of all categories no matter the one I want to view, while still separating them down by tags.

    any ideas?

    Thread Starter Kahil

    (@kahil)

    I figured it out on my own. If anyone is interested, here is a sample of the solution.

    At the top of my template, before any loops, I have the following code to check to see what category the page I am on is and return its ID.

    <?php foreach(get_the_category() as $category)
          { $thecat = $category->cat_ID; } ?>

    Then, at the start of each loop I have the following. This code is set to call specific, constant post tags in respect to the particular category archive I am on.

    <h2>30 Sheets</h2>
              <?php query_posts('cat=' . $thecat . '&tag=30-sheets&order=ASC'); ?>
              <?php if (have_posts()) : ?>
              <?php while (have_posts()) : the_post(); ?>
    
              ---- THE CONTENT YOU WANT TO SHOW GOES HERE ----
    
              <?php endwhile; ?>
    
              <?php else : ?>
              <div id="page">
              <p class="center">There are no records for this media.</p>
              </div>
    
              <?php endif; ?>
    
              <h2>Mall Kiosks</h2>
              <?php query_posts('cat=' . $thecat . '&tag=mall-kiosks&order=ASC'); ?>
              <?php if (have_posts()) : ?>
              <?php while (have_posts()) : the_post(); ?>
    
              ---- THE CONTENT YOU WANT TO SHOW GOES HERE ----
    
              <?php endwhile; ?>
    
              <?php else : ?>
              <div id="page">
              <p class="center">There are no records for this media.</p>
              </div>
    
              <?php endif; ?>

    You can do this for as many loops and tags as you like.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Page where posts are grouped and then sorted alphabetically’ is closed to new replies.