Archived topic
Adding Previous/Next links to custom post types
6 replies · Started by Mike on June 13, 2017
Hello one and all!
Is there an easy way to add the previous/next links to custom post types? I noticed in a recent changelog there was a new filter added that looks like it has to do with prev/next links. How does one enable that on specific post types?
All the best,
Michael
Hi there,
I think those filters are for switching out the next/prev link text itself.
Will confirm with Tom :)
This should help though: https://generatepress.com/forums/topic/nextprevious-post-links-on-cpt/#post-326390
That code worked thank you. Is there a way of adding multiple custom post types into that code as opposed to using the same block of code for different post types?
I tried adding things, bars, clubs cpt's into it but it didn't work:
add_action( 'generate_after_entry_content', 'tu_custom_post_type_post_nav' );
function tu_custom_post_type_post_nav() {
if ( 'things , bars , clubs' == 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;
}
Try this:
add_action( 'generate_after_entry_content', 'tu_custom_post_type_post_nav' );
function tu_custom_post_type_post_nav() {
if ( in_array(get_post_type(), array('things','bars','clubs') ) ) : ?>
<footer class="entry-meta">
<?php generate_entry_meta(); ?>
<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
</footer><!-- .entry-meta -->
<?php endif;
}
Made a mistake. Edited again...
Hello Leo,
Worked like a charm! Thank you, and as ever, this forum provides support beyond reproach :)
All the best,
Michael
You're very welcome :)