如何自定义wordpress功能:标签


How to customize wordpress function: the tags?

在我的wordpress帖子中,我包含了使用wordpress功能的标签

<?php the_tags( $before, $sep, $after ); ?> 

我的实际Css:

.postclass{
  margin:10px 0px 10px 0px;
  }
.posttag{
  font-size:10px;
  float:left;
  color:#212121;
  margin-right:15px;
  padding:5px;
  border-radius:2px;
  background:black;
}

在我的模板:

<div class="postclass">
     <?php the_tags( '<p class="posttag">', ',', '</p>' ); ?>
</div>

这给了我所有的标签在相同的黑色背景。我怎么能得到每个标签文本与黑色背景,每个由逗号分隔?

下面的示例:http://codex.wordpress.org/Function_Reference/get_the_tag_list

<div class="postclass">
     <?php the_tags( '<p class="posttag">', '</p><p class="posttag">', '</p>' ); ?>
</div>

这将在<p class="posttag">[link]</p>中单独包装所有标签。

更接近你的jsfield:

PHP

<?php the_tags( '<ul class="postclass"><li>', ',</li><li>', '</li></ul>' ); ?>
CSS

ul.postclass li {
    float: left;
}
ul.postclass li a {
    padding: 5px;
    background-color: black;
}

对于the_tags()不能自定义<a>标记本身,就像在jsfiddle中一样。你只能把它包起来。要实现这一点,您必须使用get_the_terms(),它将返回可以后处理的标记对象数组。

应该可以:

  1. 在你的WordPress post.php中添加一个div类,后面跟着这样的标签函数:
<div class="postclass">
<?php echo esc_html__( '', 'posttag' ); ?>
</div>

添加这个,如果你需要"#"

<div class="postclass">
<?php echo esc_html__( '', 'posttag' ); ?><?php the_tags( "#", "#" ); ?>
</div>
  • 在你的CSS中:
  • .postclass{
      font-size:10px;
    }
    .postclass a{
      text-decoration: none;
      padding:5px 10px;
      font-size:10px;
      color:white;
      border-radius:3px;
      background:black;
    }
    

    工作示例:https://koreanwave.org
    (在桌面:将鼠标悬停在图像底部)
    (移动端:hover @USER-NAME)