How to remove a list from <? Php the_category ()?>

I am using wordpress and I am wondering how to get only the permalink and category name of the message when using:

<?php the_category() ?>

The above list displays a list, and I just want to be able to bind a permalink and a category in my own markup

+3
source share
1 answer

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);;
} 
?>
+7
source

Source: https://habr.com/ru/post/1749931/


All Articles