简体   繁体   中英

echo category name as a link

I have the following code and instead of the 'read more' link I want it to display the name of the category as the link. Does anybody have any idea how I can achieve this?

    $the_cat = get_the_category($post->ID);
    $category_name = $the_cat[0]->cat_name;
    $category_link = get_category_link( $the_cat[0]->cat_ID );
    $slider_gallery.= '<br/><span class="chpcs_more"><a href="'.$category_link.'">read more</a></span>';

Thanks

尝试这个

$slider_gallery.= '<br/><span class="chpcs_more"><a href="'.$category_link.'">'.$category_name.'</a></span>';

Just do the same as you did with the category link like so:

$the_cat = get_the_category($post->ID);
$category_name = $the_cat[0]->cat_name;
$category_link = get_category_link( $the_cat[0]->cat_ID );
$slider_gallery.= '<br/><span class="chpcs_more"><a href="'.$category_link.'">'.$category_name.'</a></span>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM