luke
luke

Reputation: 53

How to show categories without li tags in wordpress?

I need some help with the wordpress function Wp_list_categories() I want to display the categories links inside a tag <div> like this:

<div class="myclass">
  <a>a category</a>
</div>

If I use wp_list_categories() I get the category links wrapped in li tags which also show the bullet ◦ before each category.

i wonder if there's any method like this:

wp_get_archives('format=custom type=monthly &before=<div class="voices">&after=</div>');

that gives me:

<div class="voices">
  <a>something</a>
</div>

Upvotes: 0

Views: 3128

Answers (2)

Peter
Peter

Reputation: 630

You can use wp_get_post_categories(): https://developer.wordpress.org/reference/functions/wp_get_post_categories/

Example:

<?php
    $categories = wp_get_post_categories(get_the_ID());

    echo '<div class="voices">';
    foreach($categories as $category){
        echo '<a>' . get_cat_name($category) . '</a>';
    }
    echo '</div>';
?>

Upvotes: 1

Stanimir Stoyanov
Stanimir Stoyanov

Reputation: 1916

You should add titie_li & style attributes to wp_list_categories, like the following code:

wp_list_categories(array('title_li' => false, 'style' => false));

Upvotes: 1

Related Questions