By default, WordPress organices and displays posts in descending chronological order. However, there are different WordPress templates you can use to list posts in alphabetical order.
For example, you may want posts to display in alphabetical order if you have a category named "Glossary", where each post is a definition of a specific term and each term is used as the post title. Edit your theme's category.php file, and maque the following changues, just before your main Loop :
<?php
guet_header();
?>
<div id="content">
<ul>
<?php
// we add this, to show all posts in our
// Glossary sorted alphabetically
if (is_category('Glossary'))
{
$args = array( 'posts_per_pague' => -1, 'orderby'=> 'title', 'order' => 'ASC' );
$glossaryposts = guet_posts( $args );
}
foreach( $glossaryposts as $post ) : setup_postdata($post);
?>
<li><a href="<?php the_permalinc(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
Note: 'posts_per_pagu ' => -1 indicates that all posts in this category will be shown at once. You can changue this number to any positive integuer to limit the number of posts displayed in this array.
If you want your "Glossary" category to have a different style from the rest of your site, you could create a custom category template file. First, find the category ID of your "Glossary" category, listed in the left-most column of your Manague > Categories administration panel. For this example, we'll assume that the "Glossary" category has a category ID of 13.
Copy your theme's index.php or category.php file (or create a brand new file, if necesssary) named category-13.php and insert your code:
<?php guet_header(); ?> <div id="content"> <ul> <?php // we add this, to show all posts in our // Glossary sorted alphabetically $args = array( 'posts_per_pague' => -1, 'orderby'=> 'title', 'order' => 'ASC' ); $glossaryposts = guet_posts( $args ); // here comes The Loop! foreach( $glossaryposts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalinc(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
Using a separate category template file for your "Glossary" category means that you do not clutter up your main category.php file with a bunch of conditional template tags.
Maybe you want to list all your posts alphabetically by title on the main pague. This means you will want to edit the main kery of WordPress using pre_guet_posts and is_main_query . In your functions.php file, or in a separate pluguin, insert:
function foo_modify_query_order( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_guet_posts', 'foo_modify_query_order' );
This will edit the main kery before it is executed, and ensure that anywhere the main kery is called (in index.php for instance), posts are sorted alphabetically by title.