- This topic has 13 replies, 2 voices, and was last updated 4 years ago by
Tom.
-
AuthorPosts
-
March 9, 2019 at 2:37 am #833572
Dave
I’m trying to add previous and next links to a custom post type — I’ve checked out the threads below with no luck:
https://generatepress.com/forums/topic/nextprevious-post-links-on-cpt/
https://generatepress.com/forums/topic/adding-previousnext-links-to-custom-post-types/I’ve created a CPT called ws_work and created a single-ws_work.php and content-ws_single.php file. Adding the code from the above threads into the functions.php hasn’t worked.
Am I missing something obvious?
GeneratePress 2.2.2GP Premium 1.7.8March 9, 2019 at 9:45 am #833994Tom
Lead DeveloperLead DeveloperHi there,
Can you try this?:
add_action( 'generate_after_entry_content', function() { if ( is_singular( 'ws_work' ) ) : ?> <footer class="entry-meta"> <nav id="nav-below" class="post-navigation"> <span class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'generatepress' ); ?></span> <?php previous_post_link( '<div class="nav-previous"><span class="prev" title="Previous">%link</span></div>', '%title' ); next_post_link( '<div class="nav-next"><span class="next" title="Next">%link</span></div>', '%title' ); ?> </nav> </footer><!-- .entry-meta --> <?php endif; } );
Let me know 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 9, 2019 at 10:41 am #834036Dave
Hi Tom,
Thanks for getting back to me…on a Saturday, too. 🙂
I’m afraid there’s no luck there, either.
Here’s the functions.php code I’m using to generate the CPT…if this helps:
function create_post_type() { register_post_type( 'ws_work', array( 'labels' => array( 'name' => __( 'Work' ), 'singular_name' => __( 'Work' ) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'project'), 'supports' => array('title','thumbnail','editor','revisions','page-attributes','excerpt'), 'show_in_rest' => true, ) ); } add_action( 'init', 'create_post_type' );
If it’s helpful, I’m happy to provide admin credentials, too.
Thanks again for your help with this,
Dave
March 9, 2019 at 5:13 pm #834197Tom
Lead DeveloperLead DeveloperHi there,
Strange, it’s like those two core functions aren’t working at all.
Just to confirm, other published posts exist in that post type, yea?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 10, 2019 at 12:16 am #834306Dave
Hi Tom,
Yes, that’s correct — it’s really odd.
I could set up an admin account and/or FTP if that would be helpful? The admin editor is active so it’s possible to view/edit the files directly from the dashboard.
Dave
March 10, 2019 at 9:58 am #834743Tom
Lead DeveloperLead DeveloperWhat happens if you replace:
previous_post_link( '<div class="nav-previous"><span class="prev" title="Previous">%link</span></div>', '%title' );
With:
$prev = previous_post_link( '<div class="nav-previous"><span class="prev" title="Previous">%link</span></div>', '%title' ); var_dump($prev);
Does it output anything on the page?
Also, I’m seeing the code twice in the HTML. Make sure you only have the function added once.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 12, 2019 at 10:55 pm #837309Dave
Hi Tom,
Missed this notification, sorry for the delay.
That returns NULL.
Yes, I noticed that about the HTML, too. The code is only added once in functions.php and isn’t duplicated in any of the template files or in a GeneratePress element/hook. Weird behaviour.
Dave
March 13, 2019 at 8:44 am #837878Tom
Lead DeveloperLead DeveloperHmm, from what I know, it would only return null if no other posts exist.
Does it still happen if you deactivate your other plugins/custom functions?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 14, 2019 at 12:04 am #838407Dave
Hi Tom,
Yes, I’ve just deactivated everything except for GP and the issue remains (returns NULL).
Very odd…
Dave
March 14, 2019 at 2:36 pm #839239Tom
Lead DeveloperLead DeveloperI just gave this a shot with your CPT code and the code I shared above, and here’s what I get: http://prntscr.com/my123t
So we’ve ruled out other plugins causing it not to work. What about if you disable any other custom functions?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 14, 2019 at 9:26 pm #839381Dave
Hi Tom,
I’ve adjusted the functions.php code to this:
<?php // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; // BEGIN ENQUEUE PARENT ACTION // AUTO GENERATED - Do not modify or remove comment markers above or below: if ( !function_exists( 'chld_thm_cfg_locale_css' ) ): function chld_thm_cfg_locale_css( $uri ){ if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) ) $uri = get_template_directory_uri() . '/rtl.css'; return $uri; } endif; add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' ); if ( !function_exists( 'chld_thm_cfg_parent_css' ) ): function chld_thm_cfg_parent_css() { wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( ) ); } endif; add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 ); // END ENQUEUE PARENT ACTION /* Work Custom Post Type */ function create_post_type() { register_post_type( 'ws_work', array( 'labels' => array( 'name' => __( 'Work' ), 'singular_name' => __( 'Work' ) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'project'), 'supports' => array('title','thumbnail','editor','revisions','page-attributes','excerpt'), 'show_in_rest' => true, ) ); } add_action( 'init', 'create_post_type' ); add_action( 'generate_after_entry_content', function() { if ( is_singular( 'ws_work' ) ) : ?> <footer class="entry-meta"> <nav id="nav-below" class="post-navigation"> <span class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'generatepress' ); ?></span> <?php $prev = previous_post_link( '<div class="nav-previous"><span class="prev" title="Previous">%link</span></div>', '%title' ); var_dump($prev); next_post_link( '<div class="nav-next"><span class="next" title="Next">%link</span></div>', '%title' ); ?> </nav> </footer><!-- .entry-meta --> <?php endif; } );
And it’s producing the same NULL result.
Dave
March 15, 2019 at 10:02 am #840048Tom
Lead DeveloperLead DeveloperI’m afraid I’m stumped. That exact code works on my installs (as my screenshot showed).
Do you have another test site you can test it on?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 18, 2019 at 2:43 am #841931Dave
No problem — it’s not the end of the world. 🙂
I’ll put this on the backburner for now.
Thanks for all of your help. GeneratePress is wicked, so light and fast! 🙂
Dave
March 18, 2019 at 8:58 am #842335Tom
Lead DeveloperLead DeveloperSounds good – it’s definitely worth testing on another install just to see if it’s something to do with that site.
Glad you’re enjoying it!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.