The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Trouble ordering posts in single.php (2 posts)

  1. emelgosa
    Posted 3 years ago #

    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:

     Template Name: Portfolio
    //SET QUERY ARGS, using custom post-type and order.
     $type = 'emid_portfolio';
      'post_type' => $type,
      'orderby' => 'title',
      'order' => 'ASC',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    query_posts( $args );
    	if (have_posts()) :
    		while (have_posts()) : the_post();
    			echo='<a href="'.the_permalink().'">
    		endwhile; //have_posts() : the_post()
    	endif; //have_posts()

    and then single.php looks like this:

     * The template for displaying all single posts.
    get_header(); ?>
    	<div id="single" class="site-content">
    		if (have_posts()) :
    			while (have_posts()) : the_post();
    				<h3 class="float-left"><?php the_title() ?></h3>
    					<div class="nav-single float-right">
    						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>
    			endwhile; // have_posts
    	</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.

  2. emelgosa
    Posted 3 years ago #

    Help! I've read though lots of forums and tried a lot of 'fixes' to no avail.

Topic Closed

This topic has been closed to new replies.

About this Topic