-
AuthorPosts
-
October 25, 2021 at 11:54 am #1326299
Hi Support
Is it possible to display the categories and tags of a portfolio or a Custom Post Type directly in each portfolio page (single page).
I found a function that allows you to deploy a shortcode but it is from 2015 and Enfold must have evolved because it doesn’t work anymore.
Thanks for your help!function show_portfolio_category_func($atts) { $atts = shortcode_atts( array( 'id' => '', ), $atts, 'portfolio_category' ); global $post; $the_terms = get_the_terms( $post->ID , 'portfolio_entries'); $output = ''; foreach($the_terms as $term) { if($term->parent == $atts['id']) { $termlink = get_term_link($term->term_id, $term->taxonomy); $output .= '<span class="portfolio_cat"><a href='.$termlink.'>'.$term->name.' </a></span>'; } } return $output; } add_shortcode('portfolio_category', 'show_portfolio_category_func');
October 25, 2021 at 12:14 pm #1326305Hey Ikyo,
Thank you for the inquiry.
The shortcode above should still work in the latest version. But it will only show child categories and you have to provide the ID of the parent term or category. Did you use the “portfolio_category” shortcode in a text or code block?
[portfolio_category id="ID-OF-THE-PARENT-CATEGORY"]
If you want to display all categories, replace the shortcode snippet with the following code.
function show_portfolio_category_func($atts) { global $post; $the_terms = get_the_terms( $post->ID , 'portfolio_entries'); $output = ''; foreach($the_terms as $term) { $termlink = get_term_link($term->term_id, $term->taxonomy); $output .= '<span class="portfolio_cat"><a href='.$termlink.'>'.$term->name.' </a></span>'; } return $output; } add_shortcode('portfolio_category', 'show_portfolio_category_func');
Best regards,
IsmaelOctober 26, 2021 at 5:22 pm #1326523many thanks Ismael !
I use the block code to prevent any additional html formatting.I will test this shortcode
Kind regardsOctober 27, 2021 at 12:08 pm #1326647 -
AuthorPosts
- You must be logged in to reply to this topic.