HELP – Single.php post order differs from referrer
-
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.
- The topic ‘HELP – Single.php post order differs from referrer’ is closed to new replies.