• Hi, I’m using get_the_term and trying to give each list item an ID of the taxonomy name or taxonomy ID so I can target each li individually with CSS. The problem is I don’t know how to escape certain characters so nothing I try is registering as PHP. Thanks in advance for any help.

    echo get_the_term_list($post->ID, 'example', '<li id=" id ">', '</li><li id="">', '</li>' );

    Output would be something like:
    <li id="taxonomy-name"><a href="#" rel="tag">Taxonomy Name</a></li>

Viewing 1 replies (of 1 total)
  • Thread Starter InHouse

    (@inhouse)

    A plugin developer gave me a hand with this and this is the code I’m using in case it helps anyone else.

    $id = $post->ID;
    $tax = 'mcm_category_destination';
    $op = '';
    $list = get_the_term_list($id,$tax,'','|','');
    if ($list) {
       $terms = explode('|',$list);
       $op = '<ul>';
       foreach ($terms as $term) {
          $class = sanitize_title(strip_tags($term));
          $item = "<li class='$class'>$term</li>";
          $op .= $item;
       }
       $op .= '</ul>';
    }
    echo $op;
Viewing 1 replies (of 1 total)
  • The topic ‘Give List Item the ID of the Taxonomy Name’ is closed to new replies.