【问题标题】:How to style category output如何设置类别输出的样式
【发布时间】:2012-07-04 20:07:50
【问题描述】:

我从某人那里得到了一点帮助,并且一直在使用以下内容在每个帖子下显示我的类别标题(杂志风格的 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]

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

【问题讨论】:

  • 你可以接受答案,对吧?如果是,请您接受,这样这个问题就结束了。

标签: php wordpress foreach categories


【解决方案1】:
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>[' . $category->name.']</a> ';

【讨论】:

  • 嗨弗拉德,我不能投票(仍然是菜鸟哈哈)...但感谢您抽出时间帮助我。我可以看到您的代码与 Shoguns 的代码有所不同,我只使用他的代码,因为我首先看到了他的回复。干杯人,赞赏:)
【解决方案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; = ]

【讨论】:

  • 该死的你们真是太快了。太棒了,我永远不会得到那个。非常感谢你帮助我......工作一种享受。这是一个奇怪的要求,但我认为它看起来更好!我不能投票(我还没有足够的代表点数)
猜你喜欢
  • 1970-01-01
  • 2014-07-19
  • 2018-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多