【问题标题】:How to display specific tags on top of a page?如何在页面顶部显示特定标签?
【发布时间】:2017-09-28 06:23:01
【问题描述】:
尊敬的开发者社区您好!
我正在写博客,试图解决问题。我正在尝试找到一种方法,只在标签中显示一些标签,在特定页面的顶部,以便我的访问者可以轻松地看到他们感兴趣的内容。
我已经在我的侧边栏中为所有标签使用了一个小部件。根据主题,我们的想法是在我的页面顶部显示其中的 4 到 5 个。
例如,在“我的旅行”中,对于“法国”部分,我想显示“发现”、“徒步旅行”、“美食”、“视频”、“照片”。
What I would like to do, see in black labels
非常感谢你的帮助 !!
百合
【问题讨论】:
标签:
css
wordpress
plugins
custom-wordpress-pages
【解决方案1】:
.topLabel {
background: black;
color: white;
font-family: Arial;
padding: 4px;
float: left;
margin-right: 4px;
cursor: pointer;
}
.topLabel:hover {
background: grey;
}
<a class="topLabel">Hiking</a>
<a class="topLabel">Food</a>
<a class="topLabel">Photos</a>
<a class="topLabel">Videos</a>
<a class="topLabel">Discovery</a>
也许这对你有帮助。`
【解决方案2】:
使用get_the_tags()访问帖子标签
$post_tags = get_the_tags();
if ($post_tags) {
foreach($post_tags as $tag) {
echo $tag->name . ' ';
}
}