Site logo

Archived topic

Next/Previous post links on CPT

21 replies · Started by wekhter on May 30, 2017

Viewing posts 1–15 of 22

How do you get the built-in generatepress next/previous post links to work on custom post types?

Try this:

add_action( 'generate_after_entry_content', 'tu_custom_post_type_post_nav' );
function tu_custom_post_type_post_nav() {
	if ( 'my-post-type' == get_post_type() ) : ?>
		<footer class="entry-meta">
			<?php generate_entry_meta(); ?>
			<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
		</footer><!-- .entry-meta -->
	<?php endif;
}

Adding PHP: https://docs.generatepress.com/article/adding-php/

Thanks! Another question--is there something I can do to remove next/previous on regular posts, but keep them on my CPT?

Also, I found snippets on the forum to edit the text that appears before the next/previous links, but I'd like that text to appear inside the links (so for instance the word "previous" being part of the link instead of being before the link).

Nevermind, figured out what I was doing wrong. Will the ability to have more control over page nav be added to GP Premium anytime soon?

What kind of control are you looking for?

@Tom Basic sorts of things:

1) Ability to disable next/previous on posts (an option in the blog extension?)

2) Font size

3) Change the text that appears before links

4) Alignment (so for instance, instead of having both left aligned, left align previous and right align next, or center align both on the same line)

Noted. Thanks! :)

Hi,

I've added the following to my child theme's functions.php so there will be next/previous links on "staff" CPT posts. However, all that is rendering on the front-end is
<footer class="entry-meta"> </footer>

Have I missed a step along the way? Thank you!

-----

add_action( 'generate_after_entry_content', 'tu_custom_post_type_post_nav' );
function tu_custom_post_type_post_nav() {
	if ( 'staff' == get_post_type() ) : ?>
		<footer class="entry-meta">
			<?php generate_entry_meta(); ?>
			<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
		</footer><!-- .entry-meta -->
	<?php endif;
}

Give this a shot instead:

add_action( 'generate_after_entry_content', 'tu_custom_post_type_post_nav' );
function tu_custom_post_type_post_nav() {
	if ( 'staff' == get_post_type() ) : ?>
		<footer class="entry-meta">
			<?php generate_content_nav( 'nav-below' ); ?>
		</footer><!-- .entry-meta -->
	<?php endif;
}

Let me know :)

Thanks so much, Tom -- that works!!

You're welcome :)

Hi, How do I remove/disable Next/Previous link at footer? I just upgraded to Pro, but I do not see anything to disable Next/Previous link. Thanks!

Hi David, thanks. Found another way, much easier posted by jmarc:

CSS >>>

.nav-links { display: none; }

That simply hides the nav, doesn't remove the code from the markup. I am not sure why unchecking a box in the customizer would be more complicated then adding CSS. But if it works for you, then great.

Tried all that before. Didn't work. I was only trying to remove the Previous/Next links just above footer.

This archived topic is closed to new replies.