如何设置类别输出的样式

时间:2012-07-04 10:17:02

标签: php wordpress foreach categories

我得到了一些人的帮助,并且已经使用以下内容在每个帖子(杂志样式wordpress博客)下面显示我的类别标题。它还排除了主题所依赖的类别(每个帖子必须是此猫的一部分才能显示在首页上)。

<?php
    // For each of the categories, create them as category variables
    foreach((get_the_category()) as $category) {
        // If the category is NOT the cat_name (category name) then echo some stuff
        // So grab all... except where they match cat_name (exclude basically)
        if ($category->cat_name != 'Featured') {
            echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
        }
    }
?>

但是,我想为每个显示的类别标题设置样式,即

从此

Movie Music TV Funny

到此

[Movies] [Music] [TV] [Funny]

这很容易吗?能指出我正确的方向吗?

2 个答案:

答案 0 :(得分:2)

只需修改此行:

echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>&#91;' . $category->name.'&#93;</a> '; 
//added &#91; = [ and &#93; = ]

答案 1 :(得分:1)

echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>[' . $category->name.']</a> ';