wp_tag_cloud

Sponsored Link

WordPressのバージョン2.3から利用可能です。このwp_tag_cloudは、’tag cloud’と呼ばれるもので、タグのリストを表示するテンプレートタグです。何回特定のタグが記事に割り当てられているかによって各タグのサイズが決定されます。バージョン2.8以降では、タクソノミーパラメーターは、任意のタクソノミーがクラウドを生成する基盤として使用する事ができるように追加されました。という事は例えば、投稿カテゴリーのクラウドは訪問者に提示する事ができます。

Sponsored Link

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. Beginning with Version 2.8, the taxonomy parameter was added so that any taxonony could be used as the basis of generating the cloud. That means, for example, that a cloud for posts categories can be presented to visitors.

wp_tag_cloudのテンプレートタグ使用方法

<?php wp_tag_cloud( $args ); ?>

デフォルトの使い方

<?php $args = array(
'smallest'  => 8, 
'largest'   => 22,
'unit'  => 'pt', 
'number'=> 45,  
'format'=> 'flat',
'separator' => '\n',
'orderby'   => 'name', 
'order' => 'ASC',
'exclude'   => , 
'include'   => , 
'link'  => 'view', 
'taxonomy'  => 'post_tag', 
'echo'  => true ); ?>

デフォルトでの使用を示します:

By default, the usage shows:

  • smallest – 最小タグ(最低数)はサイズ8を表示します。
  • largest – 最大タグ(最高数)はサイズ22で表示します。
  • unit – 最小と最大値のフォントサイズの単位として’pt’ (point)を記載します。
  • number – 最大45タグを表示します。
  • format – フラット(空白で区切られた)スタイルでタグを表示します。
  • separator – タグの間に空白を表示します。
  • orderby – タグを名前順にします。
  • order – 昇順の方法でタグをソートします。
  • exclude – タグを除外しません。
  • include – 全てのタグを含みます。
  • link – 表示
  • taxonomy – クラウドの基礎を投稿タグに使用します。
  • echo – 結果をエコー
  • smallest – The smallest tag (lowest count) is shown at size 8
  • largest – The largest tag (highest count) is shown at size 22
  • unit – Describes ‘pt’ (point) as the font-size unit for the smallest and largest values
  • number – Displays at most 45 tags
  • format – Displays the tags in flat (separated by whitespace) style
  • separator – Displays whitespace between tags
  • orderby – Order the tags by name
  • order – Sort the tags in ASCENDING fashion
  • exclude – Exclude no tags
  • include – Include all tags
  • link – view
  • taxonomy – Use post tags for basis of cloud
  • echo – echo the results

wp_tag_cloudのパラメーター

smallest

(integer) (optional) 最小数値を持つタグのテキストサイズです(パラメーターの単位で指定された単位です。)。

(integer) (optional) The text size of the tag with the smallest count value (units given by unit parameter).

Default: 8

largest

(integer) (optional) 最大数値を持つタグのテキストサイズです(パラメーターの単位で指定された単位です。)。

(integer) (optional) The text size of the tag with the highest count value (units given by the unit parameter).

Default: 22

unit

(string) (optional) 最小と最大の値に関係がある測定単位です。これは例えば、pt, px, em, %などの長さの値を任意のCSSにする事が出来ます。

(string) (optional) Unit of measure as pertains to the smallest and largest values. This can be any CSS length value, e.g. pt, px, em, %.

Default: ‘pt’

number

(integer) (optional) クラウドに表示するための実際のタグの数です。(全てのタグを表示するためには’0’を使用します。)

(integer) (optional) The number of actual tags to display in the cloud. (Use ‘0’ to display all tags.)

Default: 45

format

(string) (optional) クラウドを表示するフォーマットです。

(string) (optional) Format of the cloud display.

  • ‘flat’ (デフォルト)タグは、空白によって区切られ、’separator’パラメーターによって定義されています。
  • ‘list’タグは、class=’wp-tag-cloud’のULにあります。
  • ‘array’タグは、PHPで使用するための配列としてタグクラウドを返す関数と配列にあります。注:配列を返すよりむしろ表示する事は、バージョン2.5で制定されました。
  • ‘flat’ (Default) tags are separated by whitespace defined by ‘separator’ parameter
  • ‘list’ tags are in UL with a 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 Version 2.5.

separator

(string) (optional) テキスト/スペースのタグの間です。注:このパラメーターは、バージョン2.9で導入されました。

(string) (optional) The text/space between tags. Note: this parameter was introduced with Version 2.9.

Default: ‘/n’ (whitespace)

orderby

(string) (optional) タグの順序です。有効な値:

(string) (optional) Order of the tags. Valid values:

  • ‘name’
  • ‘count’

Default: name

order

(string) (optional) ソート順序。有効な値 – 大文字でなければなりません:

(string) (optional) Sort order. Valid values – Must be Uppercase:

  • ‘ASC’
  • ‘DESC’
  • ‘RAND’ tags are in a random order. Note: this parameter was introduced with Version 2.5.’RAND’タグはランダムな順序です。注:このパラメータは、バージョン 2.5で導入されました。

Default: ASC

exclude

(string) (optional) カンマで区切られたタグ(term_id) リストを除外します。例えば、’exclude=5,27′ は、term_id5か27は表示しないタグを意味します。デフォルトは何も除外しません。

(string) (optional) 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.

include

(string) (optional) カンマ区切りのタグ(term_id)リストを含めます。例えば、 ‘include=5,27’は、term_id5か27が表示したタグのみのタグを意味します。デフォルトはすべてを含めます。

(string) (optional) 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.

link

(string) (optional) 特定のタグの編集を許可するためのリンクを設定します。注:このパラメーターは、バージョン2.7で導入されました。有効な値:

(string) (optional) Set link to allow edit of a particular tag. Note: this parameter was introduced with Version 2.7. Valid values:

  • ‘view’ (Default)
  • ‘edit’

taxonomy

(string) (optional) タクソノミーはクラウドを生成するのに使用します。注:このパラメーターは、バージョン2.8で導入されました。

(string) (optional) Taxonomy to use in generating the cloud. Note: this parameter was introduced with Version 2.8.

  • ‘post_tag’ – (Default) ポストタグはクラウドのソースとして使用されます。
  • ‘category’ – ポストカテゴリーは、クラウドを生成するために使用されます。
  • ‘link_category’ – リンクカテゴリーはクラウドを生成するために使用されます。
  • ‘post_tag’ – (Default) Post tags are used as source of cloud
  • ‘category’ – Post categories are used to generate cloud
  • ‘link_category’ – Link categories are used to generate cloud

echo

(boolean) (optional) 変数に結果と維持を表示します。デフォルトはtrueです(タグクラウドを表示します)。注:このパラメーターはバージョン2.8で導入されました。有効な値:

(boolean) (optional) Show the result or keep it in a variable. The default is true (display the tag cloud). Note: this parameter was introduced with Version 2.8. Valid values:

  • 1 (true) – default
  • 0 (false)

クラウドを人気のあるタグタイトルの下に表示する方法

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

クラウドがサイズの制限がされ、名前よりカウントによってソートする方法

<?php wp_tag_cloud('smallest=15&amp;largest=40&amp;number=50&amp;orderby=count'); ?>

クラウドは配列として返しますが、表示しない方法

$tag変数は他のPHPコードで使用するためのタグクラウドが含まれます。

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

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

カテゴリークラウドを表示する方法

カテゴリーのクラウドを表示するために引き起こす為のタクソノミーの引き数を使用します。

Use the taxonomy argument to cause a cloud of categories to display.

<?php 
wp_tag_cloud( array( 'taxonomy' => 'category' ) ); 
?>

タグアーカイブを作成する方法

2.3の新しいタグ機能は素晴らしい追加ですが、wp_tag_cloud tagは、タグアーカイブを表示するために使う事が出来ます。つまり、訪問者がタグクラウドを表示しているページ任意の特定のタグをクリックして、全ての記事が同じようにタグ付けされて表示される時を意味しています。Template_Hierarchyによれば、tag.phpテンプレートが存在しない場合、archives.phpテンプレートが使用されます。このtag.phpテンプレートを構成する事によって、タグアーカイブを見る方法をカスタマイズする事が出来ます。このテンプレートは、非常に簡単にナビゲーションのトップにタグクラウドを含めます。

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.

この新しいテンプレートを使うためには、テーマファイルを追加する必要があります。
Template_Hierarchyのテンプレートに係る全てに良好なリソースです。基本は必要なステップです。

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

  1. tag.phpという名前の内容下にファイルを作成します。
  2. テーマディレクトリーにファイルをアップロードします。
  3. これは、別の方法でこのテンプレート使うタグをクリックする時、タグアーカイブにページナビゲーション内にリンクする場合のみのオプションです。
    • このテンプレートを使っている新しい空白ページを作成します。タイトルタグアーカイブのページを取得します。
  1. Create file with the contents below named tag.php.
  2. Upload file to your themes directory.
  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.
    • Create a new blank page using this template, give this page the title Tag Archive.

ステップ3上で詳しく説明しています。

To elaborate more on step three:

WordPressは、異なるページに異なるページのテンプレートを使って構成する事が出来ます。
書く=>ページ管理パネルの下部の方へ(あるいは、サイドバー上に、あなたが使っているWordPressのバージョン次第です。)、”Page Template”にドロップダウンのラベルが表示されています。そこから、あなたはこの特定のページを表示する時に使われるテンプレートを選択する事ができます。

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.

<?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(); ?>

スタイリングはこのテンプレートに追加されていないことに注意してください。良い方法は、あなたの使っているテーマのsingle.phpテーマファイルを見て構造を究明する事です。

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.

変更ログ

  • 2.9 :
    • Added the separator parameter.
  • 2.8 :
    • Added the taxonomy parameter.
    • Added the echo parameter.
  • 2.7 :
    • Added the link parameter.
  • 2.5 :
    • Added ‘RAND’ order for the order parameter to return tags in a random order.
    • Added ‘array’ format for the format parameter to return an array.
  • Since: 2.3

ソースファイル

wp_tag_cloud()は、wp-includes/category-template.php内に位置しています。

wp_tag_cloud() is located in wp-includes/category-template.php.

関連テンプレートタグ

the_tags, tag_description, single_tag_title, wp_tag_cloud, wp_generate_tag_cloud, get_tags, get_the_tags, get_the_tag_list, get_tag_link

Sponsored Link