WordPress: Template Tags/wp tag cloud:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
第9行: 第9行:
===默认用法===
===默认用法===


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





2008年7月19日 (六) 11:11的版本

描述

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

用法

<?php wp_tag_cloud(''); ?>

例子

默认用法

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


默认情况下,用法显示:

  • smallest - 最小的标签(最低的数目),大小为8。
  • largest - 最大的标签(最高的数目),大小为22。
  • unit - 描述'pt' (point)作为最小的和最大的参数值的字体大小的单位。
  • number - 最多显示45个标签
  • format - 以平面格式显示标签(由空格分开)
  • orderby - 根据名称给标签排序
  • order - 将标签按升序分类
  • exclude - 不删除任何标签
  • include - 包含所有标签

受欢迎的标签下面显示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; ?>

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

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

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

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

smallest
(integer) 拥有最少的参数值的标签文本大小。(unit参数给予的单位)。
largest
(integer) 拥有最高的参数值的标签文本大小。(unit参数给予的单位)。
unit
(string) 关于最小最大值的测量单位。可以是任何CSS长度单位,例如pt, px, em, %; 默认是 pt (points)。
number
(integer) 真正显示在cloud中的标签的数目。(使用'0'显示所有的标签。)
format
(string) 显示的cloud的格式。
  • 'flat' 默认)标签由空格分开。
  • 'list' 标签在UL中,拥有一个class='wp-tag-cloud'


  • 'array' 标签在一个数组中而且函数返回标签cloud作为一个数组用在PHP中 注:数组返回而不是显示,创立于2.5版本
orderby
(string) 标签的顺序。有效的参数值:
  • 'name' (默认)
  • 'count'
order
(string) 分类顺序。有效的参数值 - 必须是大写字母:
  • 'ASC' (默认)
  • 'DESC'
  • 'RAND' 标签随机排列。注:这个参数是在2.5版本时,引进的。
exclude
(string) 列表中(term_id),用逗号分开要删除的标签。例如,'exclude=5,27'指的是带有term_id 5 或者27的标签不会显示。默认为不删除任何内容。
include
(string) 用逗号分开列表上要包含的标签(term_id)。例如,'include=5,27'指的是只会显示拥有term_id 5或者27的标签。默认为显示所有标签。

创建一个标签存档

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.