WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Order post by title (3 posts)

  1. EntarteteMuzak
    Member
    Posted 5 years ago #

    I want to order my posts in a category (without specifying the category in the script) ascending by title. So far no luck. I rifled through this and this.

    Here is my code:

    <?php if (have_posts()) : ?>
    
     	  <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
     	  <?php /* If this is a category archive */ if (is_category()) { ?>
    		<h2 class="pagetitle"><?php single_cat_title(); ?></h2>
     	  <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    		<h2 class="pagetitle">‘<?php single_tag_title(); ?>’</h2>
     	  <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    		<h2 class="pagetitle"><?php the_time('F jS, Y'); ?></h2>
     	  <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    		<h2 class="pagetitle"><?php the_time('F, Y'); ?></h2>
     	  <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    		<h2 class="pagetitle"><?php the_time('Y'); ?></h2>
    	  <?php /* If this is an author archive */ } elseif (is_author()) { ?>
    		<h2 class="pagetitle">Author Archive</h2>
     	  <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    		<h2 class="pagetitle">Blog Archives</h2>
    
    <?php } ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <h3 id="post-<?php the_ID(); ?>" class="articletitle"><?php the_title(); ?></h3>
    
    				<div class="entry">
    					<?php the_content() ?>
    				</div>
    
    				<?php edit_post_link('Edit', '<div class="edit">', '</div>'); ?>
    
    		<?php endwhile; ?>
    
    <br /><br />
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Newer') ?></div>
    			<div class="alignright"><?php previous_posts_link('Older &raquo;') ?></div>
    		</div>
    
    	<?php else :
    
    		if ( is_category() ) { // If this is a category archive
    			printf("<h2 class='center'>Category ‘ %s ’ is empty</h2><br /><br />", single_cat_title('',false));
    		} else if ( is_date() ) { // If this is a date archive
    			echo("<h2>No posts match your query</h2>");
    		} else if ( is_author() ) { // If this is a category archive
    			$userdata = get_userdatabylogin(get_query_var('author_name'));
    			printf("<h2 class='center'>No posts match your query</h2>", $userdata->display_name);
    		} else {
    			echo("<h2 class='center'>No posts match your query.</h2>");
    		}
    
    	endif; ?>
  2. iridiax
    Member
    Posted 5 years ago #

    You could create a category.php file with this in it:

    <ul>
    <?php $posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=-1'); while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
  3. EntarteteMuzak
    Member
    Posted 5 years ago #

    Thanks, but I solved it using this plugin:
    http://www.reflectionmedia.ro/2008/12/wp-post-sorting-plugin/

Topic Closed

This topic has been closed to new replies.

About this Topic