- This topic has 15 replies, 2 voices, and was last updated 7 years, 2 months ago by Tom.
-
AuthorPosts
-
September 7, 2017 at 9:24 am #381103wekhter
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 toif{}
) and I think that’s getting in my waySeptember 8, 2017 at 12:23 am #381484TomLead DeveloperLead DeveloperWhat exactly did you need to customize? Overwriting the entire function like that probably isn’t the best method.
Let me know ๐
September 8, 2017 at 6:53 am #381680wekhterHi 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.
September 8, 2017 at 10:14 am #381832TomLead DeveloperLead DeveloperYou 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?
September 8, 2017 at 11:39 am #381882wekhter@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.
September 9, 2017 at 10:41 am #382395TomLead DeveloperLead DeveloperIs there any way you can show me your entire function? Either in your own gist or a pastebin?
September 9, 2017 at 7:20 pm #382549wekhter@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.
September 10, 2017 at 12:47 am #382612TomLead DeveloperLead DeveloperHmm, 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?
September 10, 2017 at 12:43 pm #382897wekhter@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:
What I actually want:
September 10, 2017 at 11:28 pm #383057TomLead DeveloperLead DeveloperHmm, 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 ?>
September 11, 2017 at 8:46 am #383265wekhter@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!
September 11, 2017 at 1:43 pm #383447TomLead DeveloperLead DeveloperAha! Glad you found it ๐
September 18, 2017 at 1:29 pm #387604wekhter@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 ofgenerate_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
September 18, 2017 at 7:23 pm #387713TomLead DeveloperLead DeveloperPerhaps 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?
September 21, 2017 at 2:00 pm #389631wekhter@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.
-
AuthorPosts
- You must be logged in to reply to this topic.