Happypuppy
Member
Posted 1 year ago #
Meaby someone can help me. I need to use taxonomy slug us li class for my portfolio theme.
Here is my code. It only get's taxonomy name but I need taxonomy slug.
<li class="<?php $terms_as_text = get_the_term_list( $post->ID, 'myportfolio', '', ' ', '' ) ;
echo strip_tags($terms_as_text); ?> all">
Thanks. :)
digitalrenewal
Member
Posted 9 months ago #
im trying to do this exact same thing and have the exact same problem. cant figure out how to convert name to slug...
i did get this working, but when you assign 2 categories to a post it acts kinda funny. It doesnt list all of the categories in a row to use as class identifiers
<?php
$taxonomy = 'your custom taxonomy';
$terms = get_the_terms( $post->ID , $taxonomy );
if ( !empty( $terms ) ) :
foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy );
if ( !is_wp_error( $link ) )
echo '<li class="all ' . $term->slug . '">';
}
endif;
?>
hoping someone knows the right way to do this. ive been working on this for days.