首页 文章

如何设置类别输出的样式

提问于
浏览
1

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

<?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> ';
        }
    }
?>

但是,我想设置每个显示的类别 Headers ,即;

由此

Movie Music TV Funny

对此

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

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

2 回答

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

相关问题