我正在尝试使用不同颜色设置类别名称的样式。
这是我的PHP:
<?php
foreach((get_the_category()) as $category) {
if (is_category('5') ) {
echo '<a class="featured" href="' . get_category_link( $category->cat_ID ) . '">' . $category->cat_name . '</a>';}
else {
echo '<a href="' . get_category_link( $category->cat_ID ) . '">' . $category->cat_name . '</a> ';}
}
?>
它没有返回错误,但它也没有... 我做错了什么?
以下是我正在处理的页面:
http://216.172.178.12/~saracimi/eng/
并且代码片段相对于页面中心的矩形框。
非常感谢!
答案 0 :(得分:0)
is_category将返回true。你需要检查类别ID,所以试试:
foreach((get_the_category()) as $category) {
if ($category->cat_ID == 5 ) {
echo '<a class="featured" href="' . get_category_link( $category->cat_ID ) . '">' . $category->cat_name . '</a>';
} else {
echo '<a href="' . get_category_link( $category->cat_ID ) . '">' . $category->cat_name . '</a> ';
}
}