2011-08-03 42 views
0

我试图用不同颜色来设置类别名称。在wordpress中设计类别名称

这是我的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

当您处于该类别存档时,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> '; 
    } 
} 
+0

它的工作原理!非常感谢! – alemur

相关问题