Giter Site home page Giter Site logo

Comments (18)

currentcreative avatar currentcreative commented on June 5, 2024

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.

pattonwebz avatar pattonwebz commented on June 5, 2024

@currentcreative are you saying that the nav is moving you between POST TYPES and not just moving you through categories?

from understrap.

pattonwebz avatar pattonwebz commented on June 5, 2024

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>&nbsp;%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&nbsp;<i class="fa fa-angle-right"></i>', 'Next post link', 'understrap' ), true );
				}
				?>
			</div><!-- .nav-links -->
		</nav><!-- .post-navigation -->
		<?php
	}

from understrap.

currentcreative avatar currentcreative commented on June 5, 2024

Thank you. That just goes in functions.php somehow?

from understrap.

pattonwebz avatar pattonwebz commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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.

pattonwebz avatar pattonwebz commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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.

pattonwebz avatar pattonwebz commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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.

pattonwebz avatar pattonwebz commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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.

pattonwebz avatar pattonwebz commented on June 5, 2024

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>&nbsp;%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&nbsp;<i class="fa fa-angle-right"></i>', 'Next post link', 'understrap' ), true );
				}
				?>
			</div><!-- .nav-links -->
		</nav><!-- .post-navigation -->
		<?php
	}

from understrap.

currentcreative avatar currentcreative commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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.

currentcreative avatar currentcreative commented on June 5, 2024

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>&nbsp;%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&nbsp;<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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.