tags:

views:

147

answers:

1

I am using wordpress and I am wondering how do I get just the permalink and name of the category of a post when using:

<?php the_category() ?>

The above outputs a list and I just want to be able to wrap the permalink and category in my own markup

+2  A: 

I think you want get_the_category() and get_category_link():

<?php
// everything available
foreach((get_the_category()) as $category) { 
    echo '<span><b>';
    echo $category->cat_ID . ' ';
    echo $category->cat_name . ' '; 
    echo $category->category_nicename . ' '; 
    echo $category->category_description . ' '; 
    echo $category->category_parent . ' '; 
    echo $category->category_count . ' '; 
    echo '</b></span>';
} 
?>

<?php
// heres just the name and permalink:
foreach((get_the_category()) as $category) { 
    echo $category->category_nicename . ' '; 
    echo get_category_link($category->cat_ID);;
} 
?>
artlung