Categories: wordpress

DISPLAY CATEGORY LIST OF POST IN WORDPRESS DEVELOPMENT.

In wordpress there can be more than one category. Thus it has to be kept in unordered list <ul> . The php command get_the_category() gives the array form of all the category. If you want to separate category by only comma you can do this

<?php
$category=get_the_category();
$separator=”, “;
$catall=”;
foreach($category as $cato){
$catall=$catall.”<a href=”.get_category_link($cato->term_id).”>”.$cato->cat_name.”</a>”.$separator;
}
echo trim($catall,$separator);
?>

If you have <ul> and <li> first of all enclose by <ul> with its class and put the code.

<ul class=”td-category”>

<?php
$category=get_the_category();

$catall=”;
foreach($category as $cato){
$catall=$catall.”<li class=’entry-category’><a href=”.get_category_link($cato->term_id).”>”.$cato->cat_name.”</a></li>”;
}
echo trim($catall,$separator);
?>

</ul>

jaminrai

Recent Posts

Skype Closes Its Doors After 20 Years: A Look Back and the Apps That Faded with It

After 20 years of transforming global communication, Skype has officially ceased operations. Microsoft, which purchased…

4 months ago

The Duck and the Tortoise: A Tale of Patience and Teamwork

In a serene forest by the edge of a sparkling lake, there lived a cheerful…

5 months ago

10 Smart Strategies for a Secure and Enjoyable Retirement

Retiring comfortably is a goal many aspire to achieve, and with the right strategies, it’s…

6 months ago

Troubleshooting a Slow Computer

Is your computer running frustratingly slow? Don't worry; you're not alone in facing this common…

6 months ago