WordPress.org

Ready to get started?Download WordPress

Forums

Get taxonomy slug (2 posts)

  1. Happypuppy
    Member
    Posted 3 years 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. :)

  2. digitalrenewal
    Member
    Posted 2 years 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.

Topic Closed

This topic has been closed to new replies.

About this Topic