Comments (18)
Maybe it shouldn't be doing this, but it is. I even reverted to standard archive.php and single.php templates with nothing in functions.php that would screw it up. I flushed permalinks. The previous and next post links of understrap_post_nav(); are just going through ALL my posts according to date and completely disregarding the category.
from understrap.
@currentcreative are you saying that the nav is moving you between POST TYPES and not just moving you through categories?
from understrap.
If you want to limit it to NOT move between categories, since the function is plugable, you can redefine the function in a child theme with true
passed as the first param to the get_adjacent_post
function like this:
function understrap_post_nav() {
global $post;
if ( ! $post ) {
return;
}
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( true, '', true );
$next = get_adjacent_post( true, '', false );
if ( ! $next && ! $previous ) {
return;
}
?>
<nav class="container navigation post-navigation">
<h2 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'understrap' ); ?></h2>
<div class="d-flex nav-links justify-content-between">
<?php
if ( get_previous_post_link(null, null, true) ) {
previous_post_link( '<span class="nav-previous">%link</span>', _x( '<i class="fa fa-angle-left"></i> %title', 'Previous post link', 'understrap' ), true );
}
if ( get_next_post_link(null, null, true) ) {
next_post_link( '<span class="nav-next">%link</span>', _x
( '%title <i class="fa fa-angle-right"></i>', 'Next post link', 'understrap' ), true );
}
?>
</div><!-- .nav-links -->
</nav><!-- .post-navigation -->
<?php
}
from understrap.
Thank you. That just goes in functions.php somehow?
from understrap.
Yep, just put it somewhere early in the functions.php file (it needs to be added before the actual theme would add this function itself, hence the suggestion to place it early), and it should work.
from understrap.
This did not work. I also tried to stick it in single.php in place of where understrap_post_nav();
was originally. Neither worked.
from understrap.
Having it added early in functions.php should have worked. Can you confirm for me if members
events
and meetings
are categories on your site or if they are custom post types?
Also are you using a customized version of this theme that you edit directly or are you using a child theme?
from understrap.
They're just categories, although I just added a Members custom post type to try to figure out a different solution, but I have only created 1 post with it and have not used it anywhere in the templates.
Basically, I was in the process of desperately trying to change everything after 5 hours of screwing around with this when you responded. I got as far as just making the Custom Post Type and copying the content of one "Members" category post into the Custom Post Type version.
from understrap.
It's been a really rough day trying to debug this. If you gave me pretty much everything except the add_action or add_filter part of it, could you just recommend me an example of where you think it would be early enough.
from understrap.
Paste all the code I shared right here: https://github.com/understrap/understrap/blob/main/functions.php#L41
There is no need for any add_action or add_filter calls around it. Just paste the entire function definition.
Let me know if that works or not.
from understrap.
I'm in a child theme. I initially just posted it right at the top under defined( 'ABSPATH' ) || exit;
with no add_action
and it did nothing.
from understrap.
Sorry I think I had a mistake in my suggested code. I just edited it and I think it's working now, if you could copy the code from this post again: #2181 (comment) and retry it I expect it will work for you now.
My mistake was I forgot to paste the updates to the 4 lower function calls to tell them to use links only that are in_term
.
from understrap.
No difference in the code from before. I double-checked with Diffnow since when I pasted it in nothing really changed except some lines were off. Regardless, I completely deleted the old code and pasted the new code in to give it another test and it still doesn't work. Because it's the same code. You may have failed to update #2181 (comment) correctly?
from understrap.
I can see the edit history on the comment and see the 4 lines that I changed in the latest edit. I'll paste the updated code below though as well just incase something quirky is going on with the editing.
function understrap_post_nav() {
global $post;
if ( ! $post ) {
return;
}
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( true, '', true );
$next = get_adjacent_post( true, '', false );
if ( ! $next && ! $previous ) {
return;
}
?>
<nav class="container navigation post-navigation">
<h2 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'understrap' ); ?></h2>
<div class="d-flex nav-links justify-content-between">
<?php
if ( get_previous_post_link(null, null, true) ) {
previous_post_link( '<span class="nav-previous">%link</span>', _x( '<i class="fa fa-angle-left"></i> %title', 'Previous post link', 'understrap' ), true );
}
if ( get_next_post_link(null, null, true) ) {
next_post_link( '<span class="nav-next">%link</span>', _x
( '%title <i class="fa fa-angle-right"></i>', 'Next post link', 'understrap' ), true );
}
?>
</div><!-- .nav-links -->
</nav><!-- .post-navigation -->
<?php
}
from understrap.
Yeah, there's no difference. I must have already copied+pasted your updated version before you told me you changed it. Putting it in a new spot or whatever, you know...
from understrap.
So you know what the code is doing, it's completely removing the prev/next post navigation. There are 10 posts in the members category, but your code seems to be determining that there are no other posts and so it just hides the nav.
from understrap.
I was finally able to find where I solved this problem in my last Understrap site. I copied inc/template-tags.php into my child folder and made some changes. Absolutely insane. I have no idea how I figured that out last fall and forgot all about it. I don't even understand how I figured it out, frankly.
from understrap.
The solution:
Copy template-tags.php from understrap/inc into your understrap child inc folder.
Add true
to the end of the get_previous_post_link()
and get_next_post_link()
functions like this:
<?php
if ( get_previous_post_link() ) {
previous_post_link( '<span class="nav-previous">%link</span>', _x( '<i class="fa fa-angle-left"></i> %title', 'Previous post link', 'understrap' ), true );/* , true = adds true for argument $in_same_term (default term is 'category'). - https://developer.wordpress.org/reference/functions/previous_post_link/ */
}
if ( get_next_post_link() ) {
next_post_link( '<span class="nav-next">%link</span>', _x( '%title <i class="fa fa-angle-right"></i>', 'Next post link', 'understrap' ), true ); /* , true = adds true for argument $in_same_term (default term is 'category'). - https://developer.wordpress.org/reference/functions/previous_post_link/ */
}
?>
That is the boolean $in_same_term parameter. Documentation here.
Hot tip to myself in the future:
When trying to wrangle Understrap's custom functions, open the Understrap parent theme (not child) in VS Code and search the whole folder for the function in question. From there, you can try to break down what it's doing. In this case, understrap_post_nav() only appears in 2 files (single.php and inc/template-tags.php) so it was pretty easy to track down. And it was pretty easy to understand. It's just using the Wordpress functions get_next_post_link()
and get_previous_post_link()
.
from understrap.
Related Issues (20)
- Woocommerce Mini Cart Widget Stopped working with Understrap theme HOT 2
- Please provide a short summary of the problem (approx. 50 characters) HOT 6
- Theme contains outdated copies of Woocommerce template files HOT 5
- I can't figure out a way to make tagline appear in the header area. HOT 2
- RollupError: Unexpected character '@' HOT 4
- Potential typo in phpstan.neon.dist HOT 1
- Add IE Support for using bootstrap container classes in the block editor
- outdated woocommerce template files HOT 6
- The style.min.css file is not being linked to the page HOT 4
- npm run watch is not working HOT 13
- Feature Request: Add `.nvmrc` file with the needed version of node/npm HOT 3
- wordpress navbar toggle not working after log out HOT 4
- Accessing Bootstrap javascript constructors HOT 11
- How to properly add additional js files HOT 1
- Release 1.2.4 Tracking Issue HOT 4
- Update to WPCS 3.0 (w/ PHP 8.2 support)
- Unable to build or run understrap projects - SyntaxError: Unexpected token '?' in file node_modules/lilconfig/src/index.js:161 HOT 1
- Optimize color palette generation for improved performance
- 5.3 Support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from understrap.