由特定类别制作的标签列表 - wordpress
wordpress 内置了这个功能吗?我在法典中没有看到任何内容。
codex.wordpress.org/Function_Reference/wp_tag_cloud
我有一些特定类别的页面,我想显示与这些帖子关联的所有标签。
我确实找到了这个,但我不确定它是否正确或者是否存在更好的方法(来源)(旧方法!!!!):
<?php
query_posts('category_name=html');
if (have_posts()) : while (have_posts()) : the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags_arr[] = $tag -> name;
}
}
endwhile; endif;
$tags_arr = array_unique($all_tags_arr);
?>
<ul>
<?php
foreach($tags_arr as $tag){
echo '<li>'.$tag.'</li>';
}
?>
</ul>
<?php wp_reset_query(); ?>
更新(简化):::
来自特定类别的标签列表此代码要好得多(只需更改类别名称):::
由于循环错误,最近再次更新::
<ul>
<?php
query_posts('category_name=html');
if (have_posts()) : while (have_posts()) : the_post();
if( get_the_tag_list() ){
echo $posttags = get_the_tag_list('<li>','</li><li>','</li>');
}
endwhile; endif;
wp_reset_query();
?>
</ul>
即使很难,我也可能有解决方案,如果出现新解决方案,请更新此解决方案。
Is this feature built into wordpress? i didnt see anything within the codex.
codex.wordpress.org/Function_Reference/wp_tag_cloud
I have a few pages that are category specific and i would like to show all the tags associated with those posts.
I did find this, but im not sure if its proper or if a better way exists (source)(old method!!!!):
<?php
query_posts('category_name=html');
if (have_posts()) : while (have_posts()) : the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags_arr[] = $tag -> name;
}
}
endwhile; endif;
$tags_arr = array_unique($all_tags_arr);
?>
<ul>
<?php
foreach($tags_arr as $tag){
echo '<li>'.$tag.'</li>';
}
?>
</ul>
<?php wp_reset_query(); ?>
UPDATE( simplified ):::
to make a list of tags from a specific category this code is much better(just change the category name):
::Recently updated again because of a loop error::
<ul>
<?php
query_posts('category_name=html');
if (have_posts()) : while (have_posts()) : the_post();
if( get_the_tag_list() ){
echo $posttags = get_the_tag_list('<li>','</li><li>','</li>');
}
endwhile; endif;
wp_reset_query();
?>
</ul>
Even tough i may have a solution, please update this if a new one comes around.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您找到的方法是实现您想要的目标的唯一方法。
也许你可以修改一些行,但这个概念是正确的。
目前我认为没有办法像使用核心 WordPress 功能一样过滤标签。
I think the method you've found it's the only way you can achieve what you're looking for.
Maybe you can modify some lines, but the concept is right.
at the moment i don't think there's a way to filter tags as you would using a core wordpress function.
我没有获得上面的代码来运行我的 WordPress 安装。不过我确实设法调整它直到它起作用。这是我的调整:
I did not get the code above to work my installation of WordPress. I did however manage to tweak it until it worked. Here is my tweak:
这是一个更简单的例子......只需更改类别名称即可,嘿,你就完成了。关联的标签将以列表格式打印出来。
Here is a much easier example.... Just change the category name and hey presto your done. The associated tags will print out in a list format.
首先,安装 ACF 插件并创建一个分类字段。在要显示标签的位置添加以下代码后。
First of all, install the ACF plugin and create a taxonomy field. After adding this below code where you want to display the tags.