Archived topic
Coloured category and post term buttons / badges
23 replies · Started by qpaq on October 4, 2020
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.
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.
Hi there,
Did you try replacing project_category in the code that Elvin shared with content_type?
Let us know :)
I did try with different variations like content-type or content_type but that didn’t work out.
So right now I'm seeing regular categories on top of your images, correct? What code are you using to add those?
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', ', ' ) )
);
}
}
} );
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 :)
Perfectly working, thank you very much Tom. You're a genius.
Glad I could help :)