- This topic has 23 replies, 4 voices, and was last updated 3 years, 5 months ago by Tom.
-
AuthorPosts
-
November 12, 2020 at 2:10 pm #1528983ElvinStaffCustomer 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 replaceproject_category
with the taxonomy associated with your custom post type.November 13, 2020 at 1:16 am #1529416qpaqHi 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.
November 13, 2020 at 7:40 pm #1530562TomLead DeveloperLead DeveloperHi there,
Did you try replacing
project_category
in the code that Elvin shared withcontent_type
?Let us know 🙂
November 13, 2020 at 10:59 pm #1530638qpaqI did try with different variations like content-type or content_type but that didn’t work out.
November 14, 2020 at 11:48 am #1531422TomLead DeveloperLead DeveloperSo right now I’m seeing regular categories on top of your images, correct? What code are you using to add those?
November 14, 2020 at 2:31 pm #1531509qpaqYes, 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', ', ' ) ) ); } } } );
November 15, 2020 at 11:30 am #1532574TomLead DeveloperLead DeveloperGive 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 🙂
November 15, 2020 at 12:05 pm #1532601qpaqPerfectly working, thank you very much Tom. You’re a genius.
November 15, 2020 at 2:04 pm #1532680TomLead DeveloperLead DeveloperGlad I could help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.