[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

Viewing 15 posts - 16 through 30 (of 40 total)
  • Author
    Posts
  • #1451218
    Michael

    Ok.. bordering on out of my depth, but after looking into it.. I found the category for the CPT is wpdmcategory

    So I tried..

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_singular( 'wpdmpro' ) ) {
            $args['taxonomy'] = 'wpdmcategory';
        }
    
        return $args;
    } );

    No output, did I do this correctly ?

    #1451222
    Tom
    Lead Developer
    Lead Developer

    That’s the custom taxonomy name?

    Can you post the full set of functions (related to this) that you’re using now?

    #1451228
    Michael
    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_singular( 'wpdmpro' ) ) {
            $args['taxonomy'] = 'wpdmcategory';
        }
    
        return $args;
    } );

    And the one to stay in category

    add_filter( 'generate_category_post_navigation', 'mike_stay_category' );
    function mike_stay_category()
    { 
        return 'true';
    }

    The other one for the normal nav with the thumbnails is disabled.

    #1451231
    Tom
    Lead Developer
    Lead Developer

    So instead of those two, try this:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_singular( 'wpdmpro' ) ) {
            $args['taxonomy'] = 'wpdmcategory';
            $args['in_same_term'] = true;
        }
    
        return $args;
    } );

    So this is telling the post navigation to only display links in the same term within that custom taxonomy. It will only work if that taxonomy name is correct and if other posts exist in the same term.

    Out of curiosity, does the post navigation display without same term stuff?

    #1451245
    Michael

    Nothing displaying there with or without the same terms stuff. It is strange this.

    I’ve looked on their support for anything relating to next previous, and all I can find is where they disable it for someone, by creating a custom single.php and removing the nav code. They then rename it to wpdm-single.php which it must look for in terms of customisation. Implies nav must be standard ?

    Am flummoxed.

    #1451246
    Michael

    If you want a login, I can send one if you want to see if you can spot anything ?

    #1451251
    Tom
    Lead Developer
    Lead Developer

    You’ll need this as well to tell GeneratePress to include the post meta on the CPT:

    add_filter( 'generate_footer_meta_post_types', function( $types ) {
        $types[] = 'wpdmpro';
    
        return $types;
    } );

    Anything happen with the above code only added (other functions commented out)?

    #1451255
    Michael

    Yes !!

    Am now getting navigation (and tags) , but not in the same category by the looks of things.

    https://prnt.sc/ukmjn5

    #1451257
    Tom
    Lead Developer
    Lead Developer

    Now add this:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_singular( 'wpdmpro' ) ) {
            $args['taxonomy'] = 'wpdmcategory';
            $args['in_same_term'] = true;
        }
    
        return $args;
    } );
    #1451265
    Michael

    Looking good, I didn’t know whether to delete the other one, but I just added this.. I have the previous and next in same category, but seem to be the wrong way round.. ie the one on the right is the previous one on the list. I can live with that .. can I get thumbs .. and I know asking a lot, just a title central above them to indicate to user what these links are. Or even just some text saying previous next download (as well as titles).

    Tom, this is excellent, thank you so much.

    #1451266
    Michael

    Oh forgot, can I enable the function for the regular posts alongside this as well now (currently disabled)

    #1451510
    Tom
    Lead Developer
    Lead Developer

    This code you shared last page should add thumbs:

    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;
    } );

    How are they turned on on single posts right now?

    #1451799
    Michael

    Thanks, that got the thumbnail nav back to the regular posts, but they disappeared from the CPT. The post navigation is turned on via the customiser settings.

    #1452665
    Tom
    Lead Developer
    Lead Developer

    The code above removed the post navigation from the CPT completely?

    #1452742
    Michael

    Hi Tom,

    Am getting confused.. there were 4 functions..

    The keep in category one enabled

    The first and second CPT functions you posted.

    The thumbnail function.

    I thought the second CPT one you sent was to be used instead of the first CPT one you sent, so I disabled the first function. That stopped the output at the CPT areas. After enabling both CPT functions I now get back the post nav in the custom post area (with thumbs) but they’re from different categories.

    I wasn’t sure which CPT function I had to keep, so now they’re both active. almost there with this .. just need a way to keep the CPT to the same category, and if possible add some kind of text above the previous and next to indicate that’s what they are at a glance (if possible). Am sure I could write add a hook or something, but would make more sense (lighter) if that was included with the next/previous function.

    Appreciate your work on this, didn’t realise it was going to be so tricky.

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