我一直在寻找在我的帖子下添加一个标签云,只显示与帖子相关的标签。显示的标签应为标签云格式;带有更多贴子标记的贴子标记将以更大的字体显示。
我已尝试在我的帖子下添加以下代码:
<?php wp_tag_cloud( array(
\'smallest\' => 8, // font size for the least used tag
\'largest\' => 22, // font size for the most used tag
\'unit\' => \'px\', // font sizing choice (pt, em, px, etc)
\'number\' => 45, // maximum number of tags to show
\'format\' => \'flat\', // flat, list, or array. flat = spaces between; list = in li tags; array = does not echo results, returns array
\'orderby\' => \'name\', // name = alphabetical by name; count = by popularity
\'order\' => \'ASC\', // starting from A, or starting from highest count
\'include\' => $post_id, // ID\'s of tags to include, displays none except these
\'link\' => \'view\', // view = links to tag view; edit = link to edit tag
\'taxonomy\' => \'post_tag\', // post_tag, link_category, category - create tag clouds of any of these things
\'echo\' => true // set to false to return an array, not echo it
) ); ?>
我试图使用include数组调用post id来引用post标记。但它不起作用。它显示存在的所有标记,而不是特定于帖子的标记。
有人有解决方案吗。请帮忙。
最合适的回答,由SO网友:Pontus Abrahamsson 整理而成
首先,您需要获得所有分配的tag id:s 通过调用wp_get_post_tags 因为中的include参数wp_tag_cloud 仅适用于标记id,Not page id. 因此,当您拥有所有id时,请将它们放入wp\\u tag\\u云中的include参数中,如下所示:
<?php
// Get the assigned tag_id
$tag_ids = wp_get_post_tags( $post->ID, array( \'fields\' => \'ids\' ) );
// Check if there is any tag_ids, if print wp_tag_cloud
if ( $tag_ids ) {
wp_tag_cloud( array(
\'unit\' => \'px\', // font sizing choice (pt, em, px, etc)
\'include\' => $tag_ids, // ID\'s of tags to include, displays none except these
) );
}
?>
我还删除了一些与祖先无关的参数
defaults, 仅当需要修改阵列时,才需要添加自定义参数。