[Resolved] Next / Previous Post based within category

Home Forums Support [Resolved] Next / Previous Post based within category

Home Forums Support Next / Previous Post based within category

  • This topic has 39 replies, 3 voices, and was last updated 1 year ago by Tom.
Viewing 15 posts - 1 through 15 (of 40 total)
  • Author
    Posts
  • #1449292
    Michael

    Can’t seem to find a solution by searching here in the forum, I have the next/previous links added, and styled as per instructions found here. The previous post in a category is showing as something that may be being fetched alphabetically from another category? Am terrible at trying to explain things.

    Is there a way to control the next and previous so that it works within same categories only, and for custom post categories also? Would much rather do this within the theme than try some additional plugin.

    Thanks as always.

    #1449294
    Leo
    Staff
    Customer Support
    #1449887
    Michael

    Hi Leo, thank you, yes that was what I was looking for, however it doesn’t work with custom post categories. How would I go about getting it to do that ?

    #1449888
    Michael

    Have posted a link to show where I mean, it’s the WP Download Manager custom posts..

    #1450137
    Leo
    Staff
    Customer Support

    Are you saying that the post navigation doesn’t show for that CPT or the category post navigation isn’t working in CPT?

    #1450144
    Michael

    Post navigation not showing for that CPT, category post nav working well in standard post type.

    #1450203
    Leo
    Staff
    Customer Support
    #1450258
    Michael

    Don’t seem to be getting anywhere with that, I’m getting the meta output, but no navigation.

    add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' );
    function tu_cpt_footer_meta() {
          if ( is_singular( 'wpdmpro' ) ) : ?>
            <footer class="entry-meta">
                <?php generate_entry_meta(); ?>
                <?php generate_content_nav( 'nav-below' ); ?>
            </footer><!-- .entry-meta -->
        <?php endif;
    }

    Is what I tried from the link you posted, replacing the custom post type name.

    The code I’m using for the other navigation is..

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_single() ) {
            $prevPost = get_previous_post(true);
            $prevThumbnail = isset( $prevPost ) ? get_the_post_thumbnail( $prevPost->ID ) : '';
            $nextPost = get_next_post(true);
            $nextThumbnail = isset( $nextPost ) ? get_the_post_thumbnail( $nextPost->ID ) : '';
    
            $args['previous_format'] = '<div class="nav-previous">' . $prevThumbnail . generate_get_svg_icon( 'arrow' ) . '<span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">%link</span></div>';
            $args['next_format'] = '<div class="nav-next">' . $nextThumbnail . generate_get_svg_icon( 'arrow' ) . '<span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link</span></div>';
        }
    
        return $args;
    } );

    Could I not modify the if is single line to include OR and the custom post type? It’s a bit over my head the code structure, am just theorising.

    I checked with download manager and that seems to be the way things are checked, from one of their forum posts

    if ( is_singular( 'wpdmpro' ) ) {

    #1450425
    Leo
    Staff
    Customer Support

    Sorry where did the second function come from?

    Can we try one at the time?

    Did you make sure to clear the caching plugin after adding that first block of code?

    #1450963
    Michael

    The second function came from the these forums for post nav with thumbnails, they work. The first function came from me trying to add another function, to handle the CPT from the post you pointed me to, which just outputs the meta for that post.

    I thought (hoped) that the first function could possibly be modified to check for the CPT, so that there was just one function.

    I did clear the cache also, but still just delivers the meta.

    #1451177
    Leo
    Staff
    Customer Support

    Does the first function work without the second one?

    #1451184
    Michael

    The first works with or without the second, but it’s just outputting tags no nav..

    https://prnt.sc/ukm003

    Ideally, for UX would like to keep the same layout across all.

    #1451186
    Tom
    Lead Developer
    Lead Developer

    Strange, is the custom post type using a custom taxonomy?

    #1451187
    Michael

    It’s confusing, as far as I can tell it uses categories as the name for their taxonomy, but it’s separate from the normal post categories taxonomies.

    #1451200
    Tom
    Lead Developer
    Lead Developer

    If it’s not the core category taxonomy, you may need to do this:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_singular( 'wpdmpro' ) ) {
            $args['taxonomy'] = 'the_taxonomy_slug';
        }
    
        return $args;
    } );
Viewing 15 posts - 1 through 15 (of 40 total)
  • You must be logged in to reply to this topic.