WordPress:Template Tags/wp tag cloud

来自站长百科
Fludlen讨论 | 贡献2008年7月10日 (四) 16:05的版本
跳转至: 导航、​ 搜索

Description

描述

Available with WordPress Version 2.3, this template tag wp_tag_cloud displays a list of tags in what is called a 'tag cloud', where the size of each tag is determined by how many times that particular tag has been assigned to posts.

WordPress2.3版本中拥有了这个模板标签,这个模板标签wp_tag_cloud显示了标签列表,称作'tag cloud',标签的大小,取决于一个标签向文章递交了多少次。

Usage

用法

<?php wp_tag_cloud(''); ?>
<?php wp_tag_cloud(''); ?>

Examples

例子

Default Usage

默认用法

$defaults = array('smallest' => 8, 'largest' => 22,
  'unit' => 'pt', 'number' => 45, 'format' => 'flat', 
  'orderby' => 'name', 'order' => 'ASC','exclude' => , 'include' => );

$defaults = array('smallest' => 8, 'largest' => 22,

  'unit' => 'pt', 'number' => 45, 'format' => 'flat', 
  'orderby' => 'name', 'order' => 'ASC','exclude' => , 'include' => );

By default, the usage shows:

默认情况下,用法显示:

  • smallest - The smallest tag (lowest count) is shown at size 8


  • 最小的 –最小的标签(最低的数目),大小为8。
  • largest - The largest tag (highest count) is shown at size 22
  • 最大的 –最大的标签(最高的数目),大小为22。


  • unit - Describes 'pt' (point) as the font-size unit for the smallest and largest values
  • unit –描述'pt' (point)作为最小的和最大的参数值的字体大小的单位。
  • number - Displays at most 45 tags
  • 数目 –最多显示45个标签
  • format - Displays the tags in flat (separated by whitespace) style
  • 格式 –以平面格式显示标签(由空格分开)
  • orderby - Order the tags by name
  • 顺序 –根据名称给标签排序
  • order - Sort the tags in ASCENDING fashion
  • 顺序 –将标签按升序分类
  • exclude - Exclude no tags
  • 删除 –不删除任何标签
  • include - Include all tags
  • 包含 –包含所有标签

Cloud displayed under Popular Tags title

受欢迎的标签标签下面显示Cloud

<?php if ( function_exists('wp_tag_cloud') ) : ?>
<li>
<h2>Popular Tags</h2>
<ul>
<?php wp_tag_cloud('smallest=8&largest=22'); ?>
</ul>
</li>
<?php endif; ?>


<?php if ( function_exists('wp_tag_cloud') ) : ?>
<li>
<h2>Popular Tags</h2>
<ul>
<?php wp_tag_cloud('smallest=8&largest=22'); ?>
</ul>
</li>
<?php endif; ?>


Cloud limited in size and ordered by count rather than name

大小受到限制的Cloud limited 而且根据数字而不是名称排序

<?php wp_tag_cloud('smallest=8&largest=22&number=30&orderby=count'); ?>

<?php wp_tag_cloud('smallest=8&largest=22&number=30&orderby=count'); ?>

Cloud returned as array but not displayed

Cloud作为数组返回但是不显示

The variable $tag will contain the tag cloud for use in other PHP code

 <?php $tag = wp_tag_cloud('format=array' );?>

变数$tag会在其它的PHP编码中包含标签供使用 <?php $tag = wp_tag_cloud('format=array' );?>

Parameters

参数

smallest
(integer) The text size of the tag with the smallest count value (units given by unit parameter).
最小的
(整数)拥有最少的参数值的标签文本大小。(unit参数给予的单位)。
largest
(integer) The text size of the tag with the highest count value (units given by the unit parameter).
最大的
(整数)拥有最高的参数值的标签文本大小。(unit参数给予的单位)。


unit
(string) Unit of measure as pertains to the smallest and largest values. This can be any CSS length value, e.g. pt, px, em, %; default is pt (points).
unit
(string)关于最小最大值的测量单位。可以是任何CSS长度单位,例如pt, px, em, %; 默认是 pt (points)。
number
(integer) The number of actual tags to display in the cloud. (Use '0' to display all tags.)
数目
(integer)真正显示在cloud中的标签的数目。(使用'0'显示所有的标签。)
format
(string) Format of the cloud display.

;格式:(string)显示的cloud的格式。

  • 'flat' (Default) tags are separated by whitespace
  • 'flat' (默认)标签由空格分开。
  • 'list' tags are in UL with a class='wp-tag-cloud'
  • '列出'标签在UL中,拥有一个class='wp-tag-cloud'
  • 'array' tags are in an array and function returns the tag cloud as an array for use in PHP Note: the array returned, rather than displayed, was instituted with WordPress:Version 2.5.
orderby
(string) Order of the tags. Valid values:
  • '数组'标签在一个数组中而且函数返回标签cloud作为一个数组用在PHP中 注:数组返回而不是显示,创立于2.5版本
顺序
(string)标签的顺序。有效的参数值:
  • 'name' (Default)
  • 'count'
order
(string) Sort order. Valid values - Must be Uppercase:
  • 'ASC' (Default)
  • 'DESC'
  • 'RAND' tags are in a random order. Note: this parameter was introduced with WordPress:Version 2.5.


  • '名称' (默认)
  • '数目'
顺序
(string) 分类顺序。有效的参数值 - 必须是大写字母:
  • 'ASC' (默认)
  • 'DESC'
  • 'RAND'标签随机排列。注:这个参数是在2.5版本时,引进的。


exclude
(string) Comma separated list of tags (term_id) to exclude. For example, 'exclude=5,27' means tags that have the term_id 5 or 27 will NOT be displayed. Defaults to exclude nothing.
删除
(string)列表中(term_id),用逗号分开要删除的标签。例如,'删除=5,27'指的是带有term_id 5 或者27的标签不会显示。默认为不删除任何内容。
include
(string) Comma separated list of tags (term_id) to include. For example, 'include=5,27' means tags that have the term_id 5 or 27 will be the only tags displayed. Defaults to include everything.

;包含:(string)用逗号分开列表上要包含的标签(term_id)。例如,'包含=5,27'指的是只会显示拥有term_id 5或者27的标签。默认为显示所有标签。


Creating a Tag Archive

创建一个标签存档

While the new tagging feature in 2.3 is a great addition, the wp_tag_cloud tag can be used to display a Tag Archive. What this means is that when a visitor clicks on any particular tag a page displaying the tag cloud and all posts tagged the same will be displayed. According to the Template_Hierarchy if a tag.php template does not exist then the archives.php template will be used. By making this tag.php template you can customize the way your Tag Archive will look, this template includes the tag cloud at the top for very easy navigation.

虽然这个新的标签功能是2.3版本中添加的一个重要功能,wp_tag_cloud标签可以被用来显示标签存档。这指的是,当一个访客在一个显示标签的网页上点击任何标签的时候,标签cloud和所有标签相同的文章都会显示。根据Template_Hierarchy,如果tag.php模板不存在,那么就会使用archives.php。通过制作这个tag.php模板,你可以自定义你的博客归档的外观,这个模板在顶端包含有标签cloud,使得导航变得相当简单。

To do this a new template will need to be added to your theme files. These are good resources for everything pertaining to templates, Template_Hierarchy. Basic steps needed are

要做到这一点,要将一个新的模板添加到你的主题文件中。有许多关于 模板, Template_Hierarchy的资源。基本的步骤是:

  • 1. Create file with the contents below named tag.php.
  • 1.创建文件,文件中有内容,文件名为tag.php。
  • 2. Upload file to your themes directory.
  • 2.将文件上传到你的主题目录中。
  • 3. This is optional only if you would like to have a link in your page navigation to the Tag archive, otherwise when clicking on a tag this template will be used.
  • 3. 如果你希望网页导航中有一个链接,链接到标签归档,这是可选择的,否则的话,点击标签,就会用到这个模板。


    • Create a new blank page using this template, give this page the title Tag Archive.
    • 使用这个模板创建一个新的空白网页,将这个网页赋予标题为标签存档。

To elaborate more on step three. 详细描述第三步。

WordPress can be configured to use different Page Templates for different Pages. Toward the bottom of the Write->Write Page administration panel (or on the sidebar, depending on which version of WordPress you are using) is a drop-down labeled "Page Template". From there you can select which Template will be used when displaying this particular Page.

可以设置WordPress,为不同的网页使用不同的网页模板。在写->编写网页管理面板的底部(或者在工具条上,取决于你正在使用哪个版本的WordPress)是一个下拉列表,标记为"网页模板"。在这个模板上,你可以选择显示这个特殊的网页的时候,使用哪个模板。

<?php /*
Template Name: Tag Archive
*/ ?>
<div>
<?php get_header(); ?>
<h2>Tag Archive</h2>
<?php wp_tag_cloud(''); ?>
	<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
	</div>
<?php if (have_posts()) : ?>
		<?php while (have_posts()) : the_post(); ?>
		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
	<div class="entry">
	<?php the_content('Read the rest of this entry »'); ?>
	</div>

	<?php endwhile; ?>
	<?php endif; ?>
</div>
<?php get_footer(); ?>


<?php /*
模板名称: 标签归档
*/ ?>
<div>
<?php get_header(); ?>
<h2>Tag Archive</h2>
<?php wp_tag_cloud(''); ?>
	<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
	</div>
<?php if (have_posts()) : ?>
		<?php while (have_posts()) : the_post(); ?>
		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
	<div class="entry">
	<?php the_content('阅读这篇文章的其余部分 »'); ?>
	</div>

	<?php endwhile; ?>
	<?php endif; ?>
</div>
<?php get_footer(); ?>


Please Note that styling has not been added to this template. A good way to determine the structure that your theme uses is to view the single.php theme file.

请注意这个模板没有添加样式。决定你的主题使用什么结构的一个好办法,就是访问single.php主题文件。

Related

相关的

模板:Tag post Tags

模板:PHP Function Tag Footer

This page is [[WordPress::Category:Stubs|marked]] as incomplete. You can help Codex by expanding it.

模板:标签文章 标签

This page is [[WordPress::Category:Stubs|marked]] as incomplete. You can help Codex by expanding it.