WordPress.org

Support

Support » How-To and Troubleshooting » Terms as links with slugs as link class

Terms as links with slugs as link class

  • Hi all,

    I’m trying to output a list of a posts terms from the taxonomy ‘tribe_events_cat’, and then add the term slug to it’s own list item and I’d like those list items separated with commas if possible.

    So, end result should look like this:

    Term1, Term2, Term3

    and the code should look something like this:

      <li class=”term1″>Term1,
      <li class=”term2″>Term2,
      <li class=”term3″>Term3

    If the li could have links to the term archives, even better.

    So far I’ve tried both the following but neither of them work:

    ` <?php echo ‘<ul class=”styles”>’;
    echo get_the_term_list( $post->ID, ‘tribe_events_cat’, ‘<li class=”term_link ‘.$term->slug.'”>’, ‘,</li><li>’, ‘</li>’ );
    echo ‘</ul>’;
    ?>`

    and

    `<?php $terms = get_the_term_list($post->ID, ‘tribe_events_cat’);
    $count = count($terms);
    if ( $count > 0 ){
    echo ‘<ul>’;
    foreach ( $terms as $term ) {
    echo ‘<li class=”term_link ‘.$term->slug.'”>’ . $term->name . ‘</li>’;
    }
    echo ‘</ul>’;
    }
    ?>
    `
    Any help would be majorly appreciated!

    Adam.

Viewing 1 replies (of 1 total)
  • Html output should have looked like this:

    <ul>
    li class="term1">Term1,</li>
    <li class="term2">Term2,</li>
    <li class="term3">Term3</li>
    </ul>
Viewing 1 replies (of 1 total)
  • The topic ‘Terms as links with slugs as link class’ is closed to new replies.
Skip to toolbar