Previous / Next Post
-
I’d like my blog to read more as a story. As in, I’d like my oldest post to be first and then the ‘next post’ link to go to newer posts. Is there a way to do this?
-
Hello.
You can paste this
function olsenlight_reverse_post_order( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'order', 'ASC' ); } } add_action( 'pre_get_posts', 'olsenlight_reverse_post_order' );in the theme’s functions.php file (preferably using a child theme) to reverse the post order.
Thanks for the reply! This does change the order of the posts. But, at the bottom of the post where there are links to previous posts and next posts, it does not change those. I’d like to be able to start on my first post, have people be able to read it, and then click next post to get to the second, but newer post, as an example.
Thanks.
In the single.php file you can move lines 56-58 below lines 59-61 and swap
<?php esc_html_e( 'Previous Post', 'olsen-light' ); ?>
with
<?php esc_html_e( 'Next Post', 'olsen-light' ); ?>Thanks again! This is getting closer. Now my oldest post has a next post link at the bottom (however it is in the previous post spot) and the newest post still has a next post link but gets you to the previous post. Any help?
Did you move the lines and then swap the code? There are two distinct modifications you need to make.
I did but must have done it wrong. The editor I’m using doesn’t have line numbers. Would you mind copying and pasting the code I should be swapping?
Or the code I should be moving?
Below is the portion of the code I changed and how it looks at this moment.
<div id=”paging” class=”group”>
<?php
$prev_post = get_previous_post();
$next_post = get_next_post();
?>
<?php if( ! empty( $prev_post ) ): ?>
” class=”paging-standard paging-newer”><?php esc_html_e( ‘Next Post’, ‘olsen-light’ ); ?>
<?php endif; ?><?php if( ! empty( $next_post ) ): ?>
” class=”paging-standard paging-older”><?php esc_html_e( ‘Next Post’, ‘olsen-light’ ); ?>
<?php endif; ?>Ah! I figured it out! The code is below in case anyone else has this issue. Thanks Nvourva for your help!
<div id=”paging” class=”group”>
<?php
$prev_post = get_previous_post();
$next_post = get_next_post();
?>
<?php if( ! empty( $prev_post ) ): ?>
” class=”paging-standard paging-older”><?php esc_html_e( ‘Previous Post’, ‘olsen-light’ ); ?>
<?php endif; ?><?php if( ! empty( $next_post ) ): ?>
” class=”paging-standard paging-newer”><?php esc_html_e( ‘Next Post’, ‘olsen-light’ ); ?>
<?php endif; ?>
</div>Resolved.
The topic ‘Previous / Next Post’ is closed to new replies.
