0
<ul class="list-inline">
  <li class="list-inline-item">Category 1</li>
  <li class="list-inline-item">Category 2</li>
  <li class="list-inline-item">Category 3</li>
</ul>

I am trying to get a similar output with wp_list_categories() function currently i am trying the code below

<ul class="list-inline">  
<?php wp_list_categories( array(
    'title_li' => '',
    'style' => 'list',
) ); ?>
</ul>

The output of this is below

<ul class="list-inline">
  <li class="cat-item cat-item-4">
    <a href="#">Category 1</a>
  </li>
  <li class="cat-item cat-item-4">
    <a href="#">Category 1</a>
  </li>
  <li class="cat-item cat-item-4">
    <a href="#">Category 1</a>
  </li>
</ul>

Please help me to achieve the class inside li element. Any help will be appreciated.

1

Why don't you use get_categories instead. Here is an example:

$categories = get_categories();
$output = '';
if($categories) {
    $output = "<ul class="list-inline">";
    foreach($categories as $category) {
        $output .= '<li class="list-inline-item"><a href="'.get_category_link( $category->term_id) . '">'.$category->cat_name.'</a></li>';
    }
    $output .= "</ul>";
}
echo $output;

Head over here for more available modification options

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.