WordPress.org

Ready to get started?Download WordPress

Forums

Terms as links with slugs as link class (2 posts)

  1. flint_and_tinder
    Member
    Posted 1 year ago #

    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.

  2. flint_and_tinder
    Member
    Posted 1 year ago #

    Html output should have looked like this:

    <ul>
    li class="term1">Term1,</li>
    <li class="term2">Term2,</li>
    <li class="term3">Term3</li>
    </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic