im using

<?php
    foreach((get_the_category()) as $category) {
        $cats .= $category->cat_name . ', ';
    }
    echo rtrim($cats, ', ');
?>

to display the category names of a post. How would i go about out removing a specific category from this list

有帮助吗?

解决方案

Untested but something like this should work:

<?php
foreach((get_the_category()) as $category) 
{
    if($category->cat_name == "category name")
    {

    }
    else
    {
        $cats .= $category->cat_name . ', ';
    }
}
echo rtrim($cats, ', ');
?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top