Displaying Posts in Alphabetical Order
-
I’m attempting to display all my posts within the artists category in alphabetical order on the category page, and I can’t seem to get it working. I’m following these instructions: https://codex.www.ads-software.com/Alphabetizing_Posts
Here is the code in my category.php page. With this code my posts are shown alphabetically, but ALL my posts are shown (other categories as well)
<?php /** * The template for displaying Category Archive pages. */ get_header(); ?> <?php // we add this, to show all posts in our // Glossary sorted alphabetically if (is_category('artists')) { $args = array('posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC'); $artistposts = get_posts($args); } ?> <h1><?php single_cat_title(); ?></h1> <div id="artist-grid" role="main"> <?php while (have_posts()) : the_post(); ?> <?php foreach($artistposts as $post) : setup_postdata($post); ?> <a class="product_thumbnail" href="<?php the_permalink() ?>"> <?php //the_post_thumbnail grabs the post's "featured image" this feature has added theme support in the child theme functions.php ?> <?php the_post_thumbnail('thumbnail', array('class' => 'thumbnail')); ?> <?php //This piece of code figures out the corrosponding post_title of the featured image ?> <figcaption class="post_caption"> <h1><?php the_title(); ?></h1> </figcaption> </a> <!-- product_thumbnail --> <?php endforeach; ?> <?php endwhile; // end of the loop. ?> <div class="clear"></div> </div><!-- #content --> <?php get_footer(); ?>
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘Displaying Posts in Alphabetical Order’ is closed to new replies.