Reputation: 543
I'm creating a custom theme and in the single.php
file, i have the main loop, however if i navigate to different posts, all that shows up is the latest post. I could go to the different permalinks, but the only post that shows up is the latest one. How do I make it so that the correct post shows up?
I tried changing the permalinks and deleting and adding pages, but I get the same result.
Here is single.php
<?php while(have_posts()): the_post();?>
<section class="main-section">
<header>
<h1 class="section-header"><?php the_category('/');?></h1>
<ul class="section-nav">
<?php
$cat = get_the_category()[0];
$categoryPosts = get_posts(array('category' => $cat->term_id));
foreach($categoryPosts as $post): setup_postdata($post);
?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</header>
<h2 class="section-blurb"><?php the_title();?></h2>
<div class="info">
<?php the_content(); ?>
</div>
</section>
<?php endwhile;?>
Everything works..but only for the latest post. How do I make it so that the appropriate post is shown?
Upvotes: 0
Views: 129
Reputation: 714
Hi it sounds like a simple fix. Is this a child theme. Try saving the current single.php file and replace it with a new single.php file use a wp theme the following is from wp 2012 single.php markup
<?php
/**
* The Template for displaying all single posts
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<nav class="nav-single">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
<span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentytwelve' ) . '</span> %title' ); ?></span>
<span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'twentytwelve' ) . '</span>' ); ?></span>
</nav><!-- .nav-single -->
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Upvotes: 0
Reputation: 1091
you can use orderby for sorting order 'orderby'
$categoryPosts = get_posts(array('category' => $cat->term_id, 'orderby' => 'post_date', 'order' => ASC));
For reference see this link
http://codex.wordpress.org/Template_Tags/get_posts
Upvotes: 1