Support » Fixing WordPress » HELP – Single.php post order differs from referrer

  • Resolved emelgosa


    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hariprasad


    Are you facing problem with next and previous link in single.php? If yes, Check following link That may helpful.

    Below is a quote from the link you sent me.

    “The other set of navigational aids for moving through your site control the next post and previous post links typically found at the bottom of your single/permalink post, such as any single post or article you have published on your site. These direct the user to move to the next or previous post in chronological order.

    My problem is that I’d like the next and previous link to follow the order provided in the previous query, however, the problem is that it ends up showing the single posts in chronological order. Any ideas on how to fix this?



    Did you see the last section of the url that i sent to you, there is a code like

    $pagelist = get_pages('sort_column=menu_order&sort_order=asc');
    $pages = array();
    foreach ($pagelist as $page) {
       $pages[] += $page->ID;
    $current = array_search(get_the_ID(), $pages);
    $prevID = $pages[$current-1];
    $nextID = $pages[$current+1];
    <div class="navigation">
    <?php if (!empty($prevID)) { ?>
    <div class="alignleft">
    <a href="<?php echo get_permalink($prevID); ?>"
      title="<?php echo get_the_title($prevID); ?>">Previous</a>
    <?php }
    if (!empty($nextID)) { ?>
    <div class="alignright">
    <a href="<?php echo get_permalink($nextID); ?>"
     title="<?php echo get_the_title($nextID); ?>">Next</a>
    <?php } ?>
    </div><!-- .navigation -->

    I think we can specify the order of next and previous post link like this. Hope this will help you..

    Thank you,

    I used that in unison with smarter navigation plugin and it works.

    I also found that if you use a custom post order plugin it does a similar thing because it resets the default order of everything. I was trying to do this with pre_post_order but it didn’t seem to apply. I’ll have to do some more research on how the plugins do it but for now, this will work.

    Thanks for all your help,




    Good luck..

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘HELP – Single.php post order differs from referrer’ is closed to new replies.