Title: Category not sorting error
Last modified: August 19, 2016

---

# Category not sorting error

 *  [wmain00](https://wordpress.org/support/users/wmain00/)
 * (@wmain00)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/category-not-sorting-error/)
 * The current template we are using is not sorting the categories properly. Instead
   no matter what category the post is placed under the result is that upon clicking
   the link all posts are displayed, rather than the specific post.
 * The code in full is:
 *     ```
       <?php
       get_header();
       ?>
   
       <div id="single">
       <h2><?php single_cat_title(); ?></h2>
       </div>
   
       <br />
   
       <?php
       $temp = $wp_query;
       $wp_query= null;
       $wp_query = new WP_Query();
       $wp_query->query('showposts=5'.'&paged='.$paged);
       ?>
       <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
   
       <div class="post">
   
       	<div class="post-left">
       		<?php
       		$args = array(
       			'post_type' => 'attachment',
       			'numberposts' => 1,
       			'post_status' => null,
       			'post_parent' => $post->ID
       			);
       		$attachments = get_posts($args);
       		if ($attachments) {
       			foreach ($attachments as $attachment) {
       		?>
       			<div class="image-preview">
       				<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo wp_get_attachment_thumb_url($attachment->ID) ?>" border="0" alt="" /></a>
       			</div>
       		<?php } }?>
   
       		<?php the_time('j M Y') ?> <?php edit_post_link('(Edit)','',''); ?>
       	</div>
   
       	<div class="post-right">
       		<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title();?></a></h3>
   
       		<?php the_excerpt_reloaded(55, '<b><i><a><strong>', 'excerpt_rss', FALSE, '', FALSE, 1, TRUE); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><b>Read More</b></a>
       	</div>
   
       </div>
   
       <?php endwhile; ?>
   
       <?php if(function_exists('wp_pagenavi')) { ?>
   
       <?php wp_pagenavi(); // ?>
   
       <?php } else { ?>
   
       <div class="left"><?php next_posts_link('&laquo; Older Entries') ?></div>
       <div class="right"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
   
       <?php } // End if-else statement ?>
   
       <?php get_footer(); ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [wmain00](https://wordpress.org/support/users/wmain00/)
 * (@wmain00)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/category-not-sorting-error/#post-1212123)
 * BUMP

Viewing 1 replies (of 1 total)

The topic ‘Category not sorting error’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [sorting](https://wordpress.org/support/topic-tag/sorting/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [wmain00](https://wordpress.org/support/users/wmain00/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/category-not-sorting-error/#post-1212123)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
