I am having problems getting my the_category() template tag to style accordingly with the rest of my theme. I believe this is because the HTML isn't output the same way as the the_author() and the_comments() tags. I've looked into my category_template.php file but am having trouble identifying what exactly I need to tweak to get it to style the same.

Here is my code for the category post details:

                    <a href="<?php get_category_link( $category_id ); ?>" class="post-item">
                        <i class="fa fa-tags"></i>
                        <?php the_category( '&bull;' ); ?>

I am almost certain there is a filter I need to apply in the category_template.php page but am not sure what to change. For a visual demonstration look at http://blog.diginomics.com

EDIT: I've used your advice with some success. It is falling in place and styling correctly, but now I have two category links. Take a look at the page. Here is my index.php code:

<?php the_category( '&bull;' ); ?>

And here is my category_template.php:

$categories = get_the_category( $post_id );
foreach ($categories as $category){
echo '<a class="post-item" href="' . get_category_link($category->term_id) . '">' . '<li class="fa fa-tags"></li>&nbsp;' . $category->cat_name . '</a>';

1 Answer 1


get_the_category returns an array with all the categories

$categories = get_the_category();

foreach ($categories as $category){
echo '<a class="post-item" href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>';


Tha code should work, you can modify it to add the title

Also, calling the_category echoes the result, that why i'm using the this function

  • I've edited the original post to show updated code with your recommendation. Sep 8, 2014 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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