FAQ

Just another 仙台入門new weblog

­

特定のタグの投稿数を表示

2009年 5月 26日 admin

tag_id で指定する

$tag_properties = get_tag( 15 );
echo $tag_properties->count;

タグ名で指定する

<?php 
$tag_properties = get_term_by( 'name', 'タグ名, 'post_tag' ); echo $tag_properties->count; 
?>

タグスラッグで指定する

<?php 
$tag_properties = get_term_by( 'slug', 'タグスラッグ, 'post_tag' ); echo $tag_properties->count; 
?>

get_term_by()、この関数はキャッシュを利用せず、かならずデータベースへのクエリーが発生するので、多用するとレスポンスが遅くなります。

get_tagは、キャッシュを利用していますので、もしIDでの指定で問題がなければそのままget_tagを利用した方が早いレスポンスが期待できます。

function synopsis


get_term_by($field, $value, $taxonomy,
$output= OBJECT, $filter= 'raw')

param: string $field
param: string $value
param: string $taxonomy
param: string $output Either OBJECT, ARRAY_A, or ARRAY_N
return: mixed Term Row from database

.
© FAQ Entries (RSS) and Comments (RSS)