The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Give List Item the ID of the Taxonomy Name (2 posts)

  1. InHouse
    Posted 3 years ago #

    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>

  2. InHouse
    Posted 3 years ago #

    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;

Topic Closed

This topic has been closed to new replies.

About this Topic