single post page prev/next post issue
-
Hi!
When i’m viewing a single post the previous_post_link(‘%link’); and next.. goes the original order not the order of the sections i’ve created.
I know that this is the way things work.. but is there a solution for this that the prev and next links show the order that i created whith your plugin?Thx
-
Sure, will work on it.
Ok, thx 😉
Hi, any progress on this? I just ran into the same issue.
Thought I might get around it by creating a custom nav function using WP_Query to pull the section_name but instead of returning what’s expected I’m getting all posts. Any thoughts on that? I’m happy to contribute my fix code if I can just figure out why WP_Query isn’t working. Here’s the full function for the custom previous link so far:
function previous_post_link_sorted($section_name, $current_post, $format, $link) { $postsQuery = new WP_Query(array( 'section_name'=>'Work Posts', 'posts_per_page' => -1, )); if ($postsQuery->have_posts()) { $last_post = null; while ($postsQuery->have_posts()) { $postsQuery->the_post(); //var_dump($postsQuery->post); if ($postsQuery->post->ID == $current_post) { if ($i < ($postsQuery->post_count - 1)) { $href = '<a href="' . get_permalink($last_post) . '">' . $link . '</a>'; echo str_replace('%link', $href, $format) . "\n"; } } $last_post = $postsQuery->post->ID; } } }This should do it:
functions.php
function previous_post_link_sorted($section_name, $current_post, $format, $link) { query_posts(array( 'section_name' => $section_name, 'posts_per_page' => -1 )); if (have_posts()) { $last_post = null; while (have_posts()) { the_post(); if (get_the_ID() == $current_post) { if ($i < ($wp_query->post_count - 1)) { $href = '<a href="' . get_permalink($last_post) . '">' . $link . '</a>'; echo str_replace('%link', $href, $format) . "\n"; } } $last_post = get_the_ID(); } } wp_reset_query(); } function next_post_link_sorted($section_name, $current_post, $format, $link) { query_posts(array( 'section_name' => $section_name, 'posts_per_page' => -1 )); if (have_posts()) { $use_next_post = false; while (have_posts()) { the_post(); if ($use_next_post) { if ($i < ($wp_query->post_count - 1)) { $href = '<a href="' . get_permalink(get_the_ID()) . '">' . $link . '</a>'; echo str_replace('%link', $href, $format) . "\n"; break; } } else if (get_the_ID() == $current_post) { $use_next_post = true; } } } wp_reset_query(); }Usage:
<span class="nav-prev"> <?php previous_post_link_sorted('work_posts', get_the_ID(), '< %link', 'PREVIOUS'); ?> </span> <span class="nav-next"> <?php next_post_link_sorted('work_posts', get_the_ID(), '%link>', 'NEXT'); ?> </span>Thx a lot for posting solution. I’m sorry, I didn’t get time to work on this plugin.
The topic ‘single post page prev/next post issue’ is closed to new replies.