Title: Trouble ordering posts in single.php
Last modified: August 21, 2016

---

# Trouble ordering posts in single.php

 *  [emelgosa](https://wordpress.org/support/users/emelgosa/)
 * (@emelgosa)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/trouble-ordering-posts-in-singlephp/)
 * I am creating a template from scratch for the first time and am having issues
   getting single.php to follow the order of the referral page. For example, I have
   a page template that lists all posts in a specific order. Each list item links
   to the single post, from single.php I want to browse through the posts in the
   same order. This is what I have so far.
 * page-portfolio.php contains the following:
 *     ```
       <?php
       /*
        Template Name: Portfolio
        */
        get_header(); 
   
       //SET QUERY ARGS, using custom post-type and order.
        $type = 'emid_portfolio';
        $args=array(
         'post_type' => $type,
         'orderby' => 'title',
         'order' => 'ASC',
         'post_status' => 'publish',
         'posts_per_page' => -1,
         'caller_get_posts'=> 1
       );
   
       //INIT QUERY
       query_posts( $args );
   
       //INIT LOOP
       	if (have_posts()) :
       		while (have_posts()) : the_post();
   
       //OUTPUT LOOP CONTENTS
       			echo='<a href="'.the_permalink().'">
       						'.the_title().'
       				</a>';
       		endwhile; //have_posts() : the_post()
       	endif; //have_posts()
       wp_reset_query();
       get_footer();
   
       ?>
       ```
   
 * and then single.php looks like this:
 *     ```
       <?php
   
       /**
        * The template for displaying all single posts.
        */
   
       get_header(); ?>
       	<div id="single" class="site-content">
   
       		<?php
       		if (have_posts()) :
       			while (have_posts()) : the_post();
       			?>
       				<h3 class="float-left"><?php the_title() ?></h3>
   
       					<div class="nav-single float-right">
       						<?php
       						previous_post_link('%link','<span class="port-nav prev"></span>');
       						echo '<a href="'.get_site_url().'"><span class="port-nav main"></span></a>';
       						next_post_link('%link','<span class="port-nav next"></span>');
       						?>
       					</div><!-- .nav-single -->
       					<div class="clear"></div>
   
       			<?php
       			endwhile; // have_posts
       		endif;
       		?>
       	</div><!-- #single -->
   
       <?php get_footer(); ?>
       ```
   
 * I’ve tried creating a new WP_Query() as well as modifying the main query as done
   above with query_posts(). The page or category order changes but not the single.
   php order. I’ve also tried using:
 *     ```
       //Modify Posts Order
       function modify_query_order( $query ) {
           if( $query->is_main_query() ){
           	$query->set( 'orderby', 'title');
               $query->set( 'order', 'asc' );
           }
       }
       add_action( 'pre_get_posts', 'modify_query_order' );
       ```
   
 * in conjunction with archives.php. The order changes in the archives list but 
   not in the menu when in single.php Any help would be greatly appreciated.
 * Thank you.

Viewing 1 replies (of 1 total)

 *  Thread Starter [emelgosa](https://wordpress.org/support/users/emelgosa/)
 * (@emelgosa)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/trouble-ordering-posts-in-singlephp/#post-3896755)
 * Help! I’ve read though lots of forums and tried a lot of ‘fixes’ to no avail.

Viewing 1 replies (of 1 total)

The topic ‘Trouble ordering posts in single.php’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [post order](https://wordpress.org/support/topic-tag/post-order/)
 * [pre_get_posts](https://wordpress.org/support/topic-tag/pre_get_posts/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 1 reply
 * 1 participant
 * Last reply from: [emelgosa](https://wordpress.org/support/users/emelgosa/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/trouble-ordering-posts-in-singlephp/#post-3896755)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
