<?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
'exclude' => 12, // ID's of tags to exclude, displays all except these
'include' => 13, // 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
) ); ?>
如果未提供,此功能的默认大小为“pt”,这有点不寻常,而且通常不可靠,因此请确保将该参数更改为在网站上通常用于调整字体大小的方式。
更正常的字体大小
标签云通过对每个标签应用内联样式来实现不同的字体大小。 生成的字体大小可能非常奇怪,例如style='font-size:29.3947354754px;'. Mike Summers 提出了这个解决方案
<div id="tagCloud">
<ul>
<?php
$arr = wp_tag_cloud(array(
'smallest' => 8, // font size for the least used tag
'largest' => 40, // font size for the most used tag
'unit' => 'px', // font sizing choice (pt, em, px, etc)
'number' => 200, // maximum number of tags to show
'format' => 'array', // flat, list, or array. flat = spaces between; list = in li tags; array = does not echo results, returns array
'separator' => '', //
'orderby' => 'name', // name = alphabetical by name; count = by popularity
'order' => 'RAND', // starting from A, or starting from highest count
'exclude' => '', // ID's of tags to exclude, displays all except these
'include' => '', // 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
));
foreach ($arr as $value) {
$ptr1 = strpos($value,'font-size:');
$ptr2 = strpos($value,'px');
$px = round(substr($value,$ptr1+10,$ptr2-$ptr1-10));
$value = substr($value, 0, $ptr1+10) . $px . substr($value, $ptr2);
$ptr1 = strpos($value, "class=");
$value = substr($value, 0, $ptr1+7) . 'color-' . $px . ' ' . substr($value, $ptr1+7);
echo '<li>' . $value . '</li> ';
}
?>
</ul>
</div>
结果将此
<a href='url' class='tag-link-66' title='6 topics' style='font-size:29.3947354754px;'>Tag Name</a>
变为这个
<a href='url' class='color-29 tag-link-66' title='6 topics' style='font-size:29px;'>Tag Name</a>
请注意,现在链接的类名为“color-29”,它之前没有。 现在您有了一个挂钩,可以根据标签的大小为标签名称着色。
感谢本教程,我一直在努力寻找解决方案。
感谢您的信息,但我需要一些帮助。
我对 HTML 不是很擅长,但我设法在我的网站 dezineweblog.com 上制作了一个类似于这个网站 toxel.com 的标签云。
但在这个网站上,您可以看到标签是正确对齐的,并且在左侧有一个“箭头”图像。 我不知道如何在标签左侧添加这样的图像?
请您能帮我吗? 我会回到此页面查看答案。
谢谢
我想知道显示多少个标签才合适? 对于 SEO 目的来说,45 个标签太多吗?
我认为太多了……应该在 20 到 25 个之间。
我需要一个这样的标签云,但我不知道在哪里可以构建,你能给我一些 URL 吗?
感谢您的信息。 我想在不使用 CMS 软件的情况下创建链接云时遇到了这个问题。 但是定位不正确。 无论如何,感谢您的信息。
我也尝试制作一个带有标签云的网站,但没有使用 CMS。 您能告诉我您是如何做到的吗? 我不知道如何制作。
我希望在标签云中看到的是,如果我可以将其缩小到某个类别。 假设您不想显示某些类别。 因此,与其排除它们,不如包含您想要的类别。 这可能吗?
很棒的教程。 节省了我制作 WP 网站上自定义标签云的时间。
我想知道我是否也可以将其他分类法用于本教程 :)