Single post page: previous post link not working
-
When I’m on a single post page, the previous post link is a broken link to the same page as in:
.. when I should only get a link to the previous post.
It seems to add a single post link to a link to an archive page and return that.
I’m using Emphaino as a theme.
site: https://www.styleandtalent.com
Thanks for your help.
-
It’s a pretty old theme. It hasn’t been updated for a couple of years.
Have you considered updating / upgrading to a newer theme?
Thanks, wpjobz.
I’m using a custom home page. I’m using a simple single post page which should have a list of recommended posts and then then previous post link at the bottom.
Can you recommend a new theme that does a simple job?
Not that I know from memory. There are so many to choose from though….
Thanks, will take a look. Probably quicker than trying to fix the code in Emphaino.
For sure. There will be a way around it but then there are other issues like for example its not responsive.
Open it the browser and then slowly make it narrower. It should adjust so whatever device you are using it displays correctly. All newer themes do this but older themes may not.
Thanks.
is the ‘recommended‘ section part of the theme, or added via plugin or custom code?
if you have edited single.php in any way, please post the full code; also post the codes of any template parts which might get called by single.php.
the link at the bottom is a ‘previous posts‘ link, and refers possibly to the list of the ‘recommended’ posts (although it is not working for that either), not to the single post.
I could not find a link to the single ‘previous post’ on the page.
Thanks, alchymyth.
Haven’t changed the recommended section.
Link to single ‘previous post’ is broken as mentioned in top message.
Here’s the full code:
<?php /** * The Template for displaying all single posts. * * @package Emphaino * @since Emphaino 1.0 */ get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php // emphaino_content_nav( 'nav-above' ); ?> <?php get_template_part( 'content', 'single' ); ?> <?php endwhile; // end of the loop. ?> </div> <!-- #content .site-content --> </div> <div class="div_clear"></div> <div class="bottom_post"> <?php foreach((get_the_category()) as $category) { $cat=$category->cat_name . ' '; } ?> <h1 class="more_post">Recommended</h1> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php $post_id=get_the_ID(); $tags = wp_get_post_tags($post_id); $i = 0; foreach ( $tags as $tag ) { $tag_array[$i] = $tag->term_id; $i++; } $original_query = $wp_query; $wp_query = null; $args=array('posts_per_page'=>30, 'tag__in' => $tag_array, 'post__not_in' => array($post_id) ); $wp_query = new WP_Query( $args ); // query_posts(array( // // 'post_type' => 'post', // // 'tag_in' => $tag_array // // // ) ); ?> <?php if ( have_posts() ) : ?> <?php if( is_paged() ) emphaino_content_nav( 'nav-above' ); ?> <?php if ( 'dynamic_grid_excerpts' == get_theme_mod( 'posts_layout', emphaino_default_settings('posts_layout') ) ) echo '<div id="dynamic-grid" class="clearfix">'; ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to overload this in a child theme then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php if ( 'dynamic_grid_excerpts' == get_theme_mod( 'posts_layout', emphaino_default_settings('posts_layout') ) ) echo '</div> <!-- #dynamic-grid -->'; ?> <?php emphaino_content_nav( 'nav-below' ); ?> <?php else : ?> <?php get_template_part( 'no-results', 'index' ); ?> <?php endif; ?> <?php get_footer(); ?> </div><!-- #content .site-content --> </div> </div> <!-- #primary .content-area -->
By the way, doing a search on say ‘video’ and the older posts link works fine.
this function
<?php emphaino_content_nav( 'nav-below' ); ?>
adjusts its output automatically to single or index pages;
as you have changed the original$wp_query
, the function now assumes that you are referring to multiple posts;try to reset the query before calling the content nav;
example:
<?php $wp_query = null; $wp_query = $original_query; emphaino_content_nav( 'nav-below' ); ?>
Thank you, alchymyth.
It now generates links to previous and next posts, but they’re the same ones… ??
.. on every post!
It now generates links to previous and next posts
do you want to get a link to the next/previous single post of your site, or to the next/previous posts of the ‘recommended‘ list?
what is the full code of single.php right now after your changes?
Link to the recommended list, please.
Full code now:
<?php /** * The Template for displaying all single posts. * * @package Emphaino * @since Emphaino 1.0 */ get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php // emphaino_content_nav( 'nav-above' ); ?> <?php get_template_part( 'content', 'single' ); ?> <?php endwhile; // end of the loop. ?> </div> <!-- #content .site-content --> </div> <div class="div_clear"></div> <div class="bottom_post"> <?php foreach((get_the_category()) as $category) { $cat=$category->cat_name . ' '; } ?> <h1 class="more_post">Recommended</h1> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php $post_id=get_the_ID(); $tags = wp_get_post_tags($post_id); $i = 0; foreach ( $tags as $tag ) { $tag_array[$i] = $tag->term_id; $i++; } $original_query = $wp_query; $wp_query = null; $args=array('posts_per_page'=>30, 'tag__in' => $tag_array, 'post__not_in' => array($post_id) ); $wp_query = new WP_Query( $args ); // query_posts(array( // // 'post_type' => 'post', // // 'tag_in' => $tag_array // // // ) ); ?> <?php if ( have_posts() ) : ?> <?php if( is_paged() ) emphaino_content_nav( 'nav-above' ); ?> <?php if ( 'dynamic_grid_excerpts' == get_theme_mod( 'posts_layout', emphaino_default_settings('posts_layout') ) ) echo '<div id="dynamic-grid" class="clearfix">'; ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to overload this in a child theme then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php if ( 'dynamic_grid_excerpts' == get_theme_mod( 'posts_layout', emphaino_default_settings('posts_layout') ) ) echo '</div> <!-- #dynamic-grid -->'; ?> <?php $wp_query = null; $wp_query = $original_query; emphaino_content_nav( 'nav-below' ); ?> <?php else : ?> <?php get_template_part( 'no-results', 'index' ); ?> <?php endif; ?> <?php get_footer(); ?> </div><!-- #content .site-content --> </div> </div> <!-- #primary .content-area -->
try to include the ‘paged’ parameter into the query args:
$args=array('posts_per_page'=>30, 'tag__in' => $tag_array, 'post__not_in' => array($post_id), 'paged' => get_query_var( 'paged' )
or if the above does not work:
$args=array('posts_per_page'=>30, 'tag__in' => $tag_array, 'post__not_in' => array($post_id), 'paged' => get_query_var( 'page' )
and you might possibly need to remove those lines again:
$wp_query = null; $wp_query = $original_query;
- The topic ‘Single post page: previous post link not working’ is closed to new replies.