Here’s where the post navigation code lives in “content-single.php”:
<?php if ( ! get_theme_mod( 'new_standard_hide_post_nav' ) ) : ?> <?php new_standard_post_nav(); ?><?php endif; ?><?php if ( is_active_sidebar( 'after-post' ) ) : ?> <?php dynamic_sidebar( 'after-post' ); ?><?php endif; ?>
And here’s where that lives in the theme’s function files:
if ( ! function_exists( 'new_standard_post_nav' ) ) :
/**
* Display navigation to next/previous post when applicable.
*/
function new_standard_post_nav() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous ) {
return;
}
?>
<nav class="navigation post-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'new-standard' ); ?></h1>
<div class="nav-links">
<?php
previous_post_link( '<div class="nav-previous"><div class="post-nav-title">' . __( 'Older post', 'new-standard' ) . '</div>%link</div>', _x( '%title', 'Previous post link', 'new-standard' ) );
next_post_link( '<div class="nav-next"><div class="post-nav-title">' . __( 'Newer post', 'new-standard' ) . '</div>%link</div>', _x( '%title', 'Next post link', 'new-standard' ) );
?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
endif;
I’m a bit of a novice with PHP so I appreciate any guidance or help.
]]>At the bottom and top of this post, the auto-populating link to the previous post goes to a separate, unrelated page that we did not post, for the Lucky Duck online casino
Notice how it’s got our site URL, and tacks on the post URL for the casino.
Same situation with our previous legitimate post. At that page the link for next post goes to the same outside page.
Any help would be most appreciated.
]]>So here’s the problem. Click on any of the links, and you will be taken to the correct post, where information about the person is shown. But above the post, you will see the “Next” and “Previous” links at the upper right corner. To a visitor, they assume that these Next and Previous links will display the details for the next or previous name from the list on the “summary” page. And in some cases, where the posts were created chronologically, the desired effect will be witnessed (but only by accident). However, if you start with “Arthur Hair” (the last person added to the list), what you will discover is the next or previous post from our WordPress site – with no regard to the filtering and sorting criteria that was used to display the list in the first place.
Do you have a method of “knowing” which post should be displayed when the “Next” and “Previous” links are activated (i.e. using information about the filtering and sorting conditions displayed on the summary page)?
I suppose a workaround would be to check the timestamps on the posts and artificially force these timestamps to be “chronologically ordered”. This would result in the Next and Previous links probably working as expected. However, once the beginning or end of the list was reached, there would be nothing prevent the Next and Previous links from continuing to deliver content – even though there is no more content available within the chosen filter.
]]>Also I think there are a couple of bugs in v1.8, the button showed up as white with a black border and was smaller than the ‘previous’ button until I put some text in it; then the button was correct size but the font size was larger than the default setting.
]]>I have 5 total posts, all of which are in term A. 2 of the 5 are in term B. I want to exclude term A from the next and previous post links. I thought it was done like so:
$exclude_ID = 2; // Term 'A'
get_previous_post(true, $exclude_ID, 'custom_taxonomy')
get_next_post(true, $exclude_ID, 'custom_taxonomy')
What I would expect is it would ignore that the current project belongs to term A and then go to term B and find its sibling in term B. Instead, I’m getting nothing back for either previous or next even though I am certain they are both in term B. So, I’m assuming I have misunderstood how exclusions work or I have something wrong in the code.
If I remove the exclusion, it will get the next/previous posts for term A, no problem.
Any ideas?
Thanks!
Here is the code in question:
$exclude = get_term_by( 'slug', 'featured-projects', 'project_types' );
$exclude_ID = $exclude->term_id;
$prev_link = get_previous_post_link('%link', '<i class="fas fa-angle-left"></i>previous project', true, $exclude_ID, 'project_types');
$next_link = get_next_post_link('%link', 'next project<i class="fas fa-angle-right"></i>', true, $exclude_ID, 'project_types');
if (strlen($prev_link)) {
echo $prev_link;
}
if ( strlen($prev_link) && strlen($next_link) ) {
echo '<span>|</span>';
}
if (strlen($next_link)) {
echo $next_link;
}
]]>What I want to accomplish is have my single.php display posts in the same category for the previous and next posts underneath the post. The problem is that each of my posts are in multiple categories, and they are display through one of the other categories versus the one I want them to display from. Does that even make sense?
Example Categories:
Characters (parent category) (Subcategories listed below:)
– Tony
– John (This one is displaying instead.)
– Farah
– Stories (I want these ones to display.)
Now, my question is, how do I choose the category I want to be pulled from instead of the one being automatically pulled? Here is my code below (that I’ve found and been fiddling with), with what I’ve tried so far.
<?php
if (is_single() && in_category('stories')) {
$post_id = $post->ID;
$cat = get_the_category(); //I've tried changing this to my category (both ID and slug)
$current_cat_id = $cat[0]->cat_ID; //Also tried plugging ID and slug
$args = array(
'category' => $current_cat_id, //Also tried plugging ID and slug
'orderby' => 'post_date',
'order' => 'DESC'
);
$posts = get_posts($args);
$ids = array();
foreach ($posts as $thepost) {
$ids[] = $thepost->ID;
}
$thisindex = array_search($post_id, $ids);
$previd = $ids[$thisindex - 1];
$nextid = $ids[$thisindex + 1];
if (!empty($nextid)) {
?><div class="double-grid"><a rel="next" href="<?php echo get_permalink($nextid) ?>"><div class="image-tile tile-on-archive-page" style="background-image: url('<?php echo get_the_post_thumbnail_url($nextid); ?>'"> <div class="gold-button">LAST STORY >></div></div></a></div><?php
}
if (!empty($previd)) {
?><div class="double-grid"><a rel="prev" href="<?php echo get_permalink($previd) ?>"><div class="image-tile tile-on-archive-page" style="background-image: url('<?php echo get_the_post_thumbnail_url($previd); ?>'"> <div class="gold-button">NEXT STORY >></div></div></a></div><?php
}
}
?>
Any input appreciated!
]]>$nextPost = get_next_post(true);
$nextURL = get_permalink($nextPost->ID);
echo '<a class="next-product" href="';
echo $nextURL;
echo '">></a>';
It is working for POST in SAME category. How can I change it so that it works for other POST TYPES – For example PAGE or some new post type – f.e. FOTOGRAFIE. within its own TAXONOMY
Thanks
Jan
I found it easy to change just by following the guide with my last theme but I switched to the Big Brother Theme and it’s different.
I’m not sure what file I’m suppose to edit or what I’m suppose to do.
]]>On my site www.maartendemeijer.nl the secondary sidebar is where it should be on the home page (on the right) but it skips to the left in single post view.
I’ve noticed that in single post view the ‘previous post’ link and ‘next post’ link aren’t where they supposed to be as well: they appear on the right side while they should be on the bottom. Are these links perhaps ‘pushing away’ my secondary sidebar…?
I hope somebody can help with this problem. Please let me know if you need any CSS-rules from the theme I’m using to see what’s causing this skipping of elements.
By the way: I have a multisite installation and I don’t have this problem on my other sites (www.maartendemeijer.nl/improzaken and www.maartendemeijer.nl/brievenaanjan)
Kind regards
Maarten
The Netherlands
]]>By DEFAULT it:
But I NEED it:
I found this code that let me now order the Next/Prev Links alhpabetically however I still can’t show links only from same category of the post.
function filter_next_post_sort($sort) {
if (get_post_type($post) == 'post') {
$sort = "ORDER BY p.post_title ASC LIMIT 1";
}
else{
$sort = "ORDER BY p.post_date ASC LIMIT 1";
}
return $sort;
}
function filter_next_post_where($where) {
global $post, $wpdb;
if (get_post_type($post) == 'post') {
return $wpdb->prepare("WHERE p.post_title > '%s' AND p.post_type = '". get_post_type($post)."' AND p.post_status = 'publish'",$post->post_title);
}
else{
return $wpdb->prepare( "WHERE p.post_date > '%s' AND p.post_type = '". get_post_type($post)."' AND p.post_status = 'publish'", $post->post_date, $post->post_type );
}
}
function filter_previous_post_sort($sort) {
if (get_post_type($post) == 'post') {
$sort = "ORDER BY p.post_title DESC LIMIT 1";
}
else{
$sort = "ORDER BY p.post_date DESC LIMIT 1";
}
return $sort;
}
function filter_previous_post_where($where) {
global $post, $wpdb;
if (get_post_type($post) == 'post') {
return $wpdb->prepare("WHERE p.post_title < '%s' AND p.post_type = '". get_post_type($post)."' AND p.post_status = 'publish'",$post->post_title);
}
else{
return $wpdb->prepare( "WHERE p.post_date < '%s' AND p.post_type = '". get_post_type($post)."' AND p.post_status = 'publish'", $post->post_date, $post->post_type );
}
}
add_filter('get_next_post_sort', 'filter_next_post_sort');
add_filter('get_next_post_where', 'filter_next_post_where');
add_filter('get_previous_post_sort', 'filter_previous_post_sort');
add_filter('get_previous_post_where', 'filter_previous_post_where');
Note: Every post is assigned to only one category.
THANK YOU FOR HELP ME!
]]>