- サイトデザイン工事中です。ご意見をお寄せください。
- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
テンプレートタグ/wp count posts
提供:WordPress Codex 日本語版
< テンプレートタグ
WordPress 2.5 で初めて使用できるようになった、このテンプレートタグは post_type と post_status で指定した wp_posts の数を返します。
使い方
<?php wp_count_posts('type', 'status'); ?>
用例
初期設定での使用
デフォルトでは公開された記事の数を返します。
<?php $published_posts=wp_count_posts(); ?>
下書きを数える
下書きの数を返します。
<?php $draft_posts=wp_count_posts('post','draft'); ?>
ページを数える
公開されたページの数を返します。
<?php $published_pages=wp_count_posts('page','publish'); ?>
パラメータ
- type
- (文字列) 数えたい wp_posts の型。型の値は post_type と同じです。デフォルトは post です
- status
- (文字列) 数えたい wp_posts のステータス。ステータスの値は post_status と同じです。デフォルトは publish です
変更履歴
- 2.5 : 新規テンプレートタグ
関連
the_ID, the_title, the_title_attribute, single_post_title, the_title_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, wp_link_pages, next_post_link, next_posts_link, previous_post_link, previous_posts_link, posts_nav_link, sticky_class, the_meta
最新英語版: WordPress Codex » Template Tags/wp_count_posts (最新版との差分)