I am trying to figure out how to display the category of an article, and a link to the category. Any help would be greatly appreciated.
Leave a Reply
You must be logged in to post a comment.
I am trying to figure out how to display the category of an article, and a link to the category. Any help would be greatly appreciated.
You must be logged in to post a comment.
If you want to do this on post page you can add something like the following to your single.php file of your theme.
Here’s some info that will be of use:
http://codex.wordpress.org/Template_Tags/wp_list_categories
Basically you can call:
<?php wp_list_categories( $args ); ?>
and this will output what you’re looking for.Thr
$args
parameter is an array of settings strings that lets you change the order, style, depth etc, on links returned.Note that:
<?php the_category(', ') ?>
will display the category as a link. which is good…. but if you want only the category URL (that is, the category link only), then you will have to use the<?php get_category_link($category_ID); ?>
the$category_ID
is required. once you fix that in, the category URL will be returned.Consider the example:
Now you can see how we got the category ID and then using it to get the category Link.
Hope this answers your question well enough?
You can use get_the_category()