[Resolved] Customizing next/previous links in CPT w/o affecting archive

Home Forums Support [Resolved] Customizing next/previous links in CPT w/o affecting archive

Home Forums Support Customizing next/previous links in CPT w/o affecting archive

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #381103
    wekhter

    Hi, I adapted this gist: https://gist.github.com/generatepress/db03ed9158a57799a20e to customize the next/prev links for one of my CPTs.

    That worked great, but I just realized that it’s changed the paging navigation in my archives from the normal “1 2 … 4 Next” navigation to Older/newer posts.

    How do I a) keep the custom next/prev links on my CPT while b) leaving archive navigation alone? I never formally learned PHP so I have trouble with if : endif syntax (as opposed to if{}) and I think that’s getting in my way

    #381484
    Tom
    Lead Developer
    Lead Developer

    What exactly did you need to customize? Overwriting the entire function like that probably isn’t the best method.

    Let me know ๐Ÿ™‚

    #381680
    wekhter

    Hi Tom, basically I just needed to customize the next/previous links on one CPT (named ‘programpage’). I was also using this to remove next/previous links on posts. Basically, I need the next/previous links customized and also need those links to not show up on any other post type.

    #381832
    Tom
    Lead Developer
    Lead Developer

    You can remove the single post navigation like this: https://generatepress.com/forums/topic/remove-it-from-source-code-to/#post-380485

    What exactly are you wanting to customize? What kind of customizations?

    #381882
    wekhter

    @Tom Well, here goes:

    programpage is basically a lesson in our psuedo-LMS. I set it up so that we could have automatic next/previous buttons for lessons, but needed to customize the text so that it 1) doesn’t include the content title of the next/previous lessons and 2) has some extra CSS classes for styling purposes. I also set it up to disable either next, previous, or both links on a per-lesson basis (we have lessons in different courses that aren’t supposed to link to each other).

    I set all that up based on this gist: https://gist.github.com/generatepress/db03ed9158a57799a20e w/ relevant changes below.

    		<?php elseif ( is_singular( 'programpage' ) ) : ?>
    
    			<h6 class="screen-reader-text"><?php _e( 'Post navigation', 'generatepress' ); ?></h6>
    			<?php if ( get_field( 'lesson_links' ) == 'next_only' ):
      				// null
      				else:
    		 		previous_post_link( '<div class="nav-previous">%link</div>', '<span class="lesson-nav">Previous</span>' );
      				endif; ?>
    			<?php if ( get_field( 'lesson_links' ) == 'previous_only' ):
      				// null
      				else:
      				next_post_link( '<div class="nav-next">%link</div>', '<span class="lesson-nav">Next</span>' );
      				endif; ?>

    The problem I’m having is that it’s also affecting CPT archives. I just want the normal “1, 2 … 5, 6” pagination at the bottom of archives, but it’s showing up as newer/older posts. I tried to get rid of the bottom section of the code in that gist but clearly I’m going about it wrong because it’s not working.

    #382395
    Tom
    Lead Developer
    Lead Developer

    Is there any way you can show me your entire function? Either in your own gist or a pastebin?

    #382549
    wekhter

    @Tom Here is the snippet I’m using to change the text: https://pastebin.com/A2sJJf1z

    I know that the last section is overriding the archive pagination but every time I’ve tried to remove that section it rendered the code invalid so I’m clearly doing something wrong there.

    #382612
    Tom
    Lead Developer
    Lead Developer

    Hmm, your code doesn’t look like it should be removing pagination on archives. Can you link me to an archive page possible so I can take a look at the code?

    #382897
    wekhter

    @Tom There is pagination, but it’s not the kind I want. Here’s a link to the archive on a site I use for testing: http://unsightly-gerbil.w3.poopy.life/animation/

    Note: I’m totally aware that the bottom looks blank because of CSS, but that’s not the issue I’m having here.

    What I have right now w/ the CSS disabled:

    Screenshot_21

    What I actually want:

    Screenshot_22

    #383057
    Tom
    Lead Developer
    Lead Developer

    Hmm, try replacing this line:

    max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>

    With this:

    <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() || is_post_type_archive() ) ) : // navigation links for home, archive, and search pages ?>

    #383265
    wekhter

    @Tom Didn’t work, but I finally got it working–I had <?php the_posts_navigation(); ?> when I needed<?php generate_paging_nav(); ?>

    Thanks for your help!

    #383447
    Tom
    Lead Developer
    Lead Developer

    Aha! Glad you found it ๐Ÿ™‚

    #387604
    wekhter

    @Tom I know it’s been a few days, but I realize that I’m seeing the following PHP notice in my debug.log:

    PHP Notice: generate_paging_nav is <strong>deprecated</strong> since version 1.3.45! Use the_posts_navigation() instead.

    As I said above, it turned out that the_posts_navigation() was my problem, since it showed “Older/Newer” navigation instead of the “1, 2 … 5, Next” archive navigation I wanted. Is there something I should be using instead of generate_paging_nav?

    I also saw this (unrelated) PHP notice in my debug.log:

    PHP Notice:  Undefined index: merge in /wp-content/plugins/gp-premium/page-header/functions/page-header.php on line 170
    PHP Notice:  Undefined index: merge in /wp-content/plugins/gp-premium/page-header/functions/page-header.php on line 172
    #387713
    Tom
    Lead Developer
    Lead Developer

    Perhaps you should try re-doing your code and make sure you’re using the latest version of the function: https://github.com/tomusborne/generatepress/blob/1.4/inc/template-tags.php#L11-L69

    What version of GPP are you using?

    #389631
    wekhter

    @Tom I’m using GP Premium 1.4.3 which is the most recent.

    Using the latest version of the function from what you linked, it’s still the same issue where there is no numeric pagination on the archives. Actually, it looks like there’s no navigation whatsoever on the archives if I look in the source code.

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