I have written up a page template that will list posts in the same category as the name of the page. I am wondering how to alter it to get it to return the posts in alphabetical order?
I have been reading over and playing with how to change the template with the Alphabetizing Posts Codex Page. I just can't seem to get it to work. It would be greatly appreciated if someone demonstrated this for me once so I can see how it is done in this context.
The following is my code for the page template:
<?php /* Template Name: Category Page */ get_header(); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="content-container"> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <?php endwhile; else: endif; ?> <?php query_posts('category_name='.get_the_title().'&post_status=publish');?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h1> <p><?php the_content(); ?> <?php endwhile; else: endif; ?> </div> <?php /*If sidebar is not disabled in Customizer, get_sidebar*/ if ( get_theme_mod( 'ctheme_remove_sidebar' ) != 1 ) : get_sidebar(); endif; get_footer(); ?>
This is one way I'm thinking of doing it. If you have any other ideas how I should approach it, let me know!
The purpose of this page will be to retrieve a list of animal names, (no date for the post, no excerpt for the post, just the name of the animal) so alphabetical order would be the most useful.