문제

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