[Resolved] Coloured category and post term buttons / badges

Home Forums Support [Resolved] Coloured category and post term buttons / badges

Home Forums Support Coloured category and post term buttons / badges

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #1528983
    Elvin
    Staff
    Customer Support

    You’ll have to change how the term list behaves.

    Try this PHP snippet:

    add_action( 'wpsp_inside_image_container', function( $settings ) {
        if ( 123 === (int) $settings['list_id'] ) {
        if ( 'projects' === get_post_type() ) {
            printf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>',
                get_the_term_list( get_the_ID(), 'project_category', '', apply_filters( 'wpsp_term_separator', ', ' ) )
            );
        } else{
            printf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>',
                get_the_term_list( get_the_ID(), $settings[ 'taxonomy' ], '', apply_filters( 'wpsp_term_separator', ', ' ) )
            );
        }
    
        }
    } );

    Replace 123 with the WPSP list id, replace projects with your custom post type slug, and replace project_category with the taxonomy associated with your custom post type.

    #1529416
    qpaq

    Hi Elvin,

    Thanks a lot. I’ve copied your code with the WPSP list number as 1987. It works but still couldn’t figure out which one is the slug and which one is the taxonomy, so still, I have the categories duplicated over the images.

    My custom post taxonomy is generated by PODS plugin. The slug for it is content_type. It’s not a custom post type but a custom taxonomy attached to regular posts.

    Content Types are ‘News’, ‘Events’, ‘Profiles’, ‘Opinions’, ‘Projects’, ‘Products’.

    On the post pages I could display the Content Types with this code {{post_terms.content_type}} on the upper left part.

    So I think I’m a bit confused here to edit the code you provided.

    #1530562
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Did you try replacing project_category in the code that Elvin shared with content_type?

    Let us know 🙂

    #1530638
    qpaq

    I did try with different variations like content-type or content_type but that didn’t work out.

    #1531422
    Tom
    Lead Developer
    Lead Developer

    So right now I’m seeing regular categories on top of your images, correct? What code are you using to add those?

    #1531509
    qpaq

    Yes, you’re right Tom. Regular categories are duplicated over the featured images. I want them to be replaced by custom taxonomy (content_type). But I assume, Elvin’s code is for custom posts. However I don’t have custom posts, I have just custom taxonomies which extends regular posts (via PODS plugin). So over the images, we should see the content_type labels.

    When I change the way Home Page Latest Articles List is sorted in WPSP from categories to content_type, I can see the content_type labels over the image but this time they are duplicated underneath the images and categories disappear.

    The code is Elvin’s code revised according to what he suggests.

    add_action( 'wpsp_inside_image_container', function( $settings ) {
        if ( 1987 === (int) $settings['list_id'] ) {
        if ( 'content_type' === get_post_type() ) {
            printf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>',
                get_the_term_list( get_the_ID(), 'content_type', '', apply_filters( 'wpsp_term_separator', ', ' ) )
            );
        } else{
            printf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>',
                get_the_term_list( get_the_ID(), $settings[ 'taxonomy' ], '', apply_filters( 'wpsp_term_separator', ', ' ) )
            );
        }
    
        }
    } );
    #1532574
    Tom
    Lead Developer
    Lead Developer

    Give this a shot:

    add_action( 'wpsp_inside_image_container', function( $settings ) {
        if ( 1987 === (int) $settings['list_id'] ) {
            printf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>',
                get_the_term_list( get_the_ID(), 'content_type', '', apply_filters( 'wpsp_term_separator', ', ' ) )
            );
        }
    } );

    Let me know 🙂

    #1532601
    qpaq

    Perfectly working, thank you very much Tom. You’re a genius.

    #1532680
    Tom
    Lead Developer
    Lead Developer

    Glad I could help 🙂

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