[Resolved] Next/Previous post links on CPT

Home Forums Support Next/Previous post links on CPT

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #326195
    wekhter

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

    GeneratePress 1.3.46
    GP Premium 1.3
    #326390
    Tom
    Lead Developer
    Lead Developer

    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/

    #326844
    wekhter

    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?

    #327023
    Tom
    Lead Developer
    Lead Developer

    What kind of control are you looking for?

    #327409
    wekhter

    @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)

    #327481
    Tom
    Lead Developer
    Lead Developer
    #457283
    Gwen

    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;
    }
    #457513
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #458811
    Gwen

    Thanks so much, Tom — that works!!

    #459000
    Tom
    Lead Developer
    Lead Developer
    #998888
    Matt

    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!

    #998918
    David
    Staff
    Customer Support

    Hi there,

    you can disable the Display post navigation in Customizer > Layout > Blog:

    https://docs.generatepress.com/article/blog-content-layout/#single

    #998951
    Matt

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

    CSS >>>

    .nav-links { display: none; }

    #998953
    David
    Staff
    Customer Support

    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.

    #998968
    Matt

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

Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.