※アクセスログの検索キーワードをヒントに記事
WordPressの記事一覧(検索結果、カテゴリ一覧、トップページ等)にて、記事の件数を表示する。
■書式:
$wp_query->found_posts
■記述例:
<?php if (have_posts()) : ?>
<p>「<?php echo wp_specialchars($s, 1); ?>」の検索結果 <?php echo $wp_query->found_posts; ?> 件</p>
<?php while (have_posts()) : the_post(); ?>
—ループ—
<?php endwhile; ?>
<p>「<?php echo wp_specialchars($s, 1); ?>」の検索結果 <?php echo $wp_query->found_posts; ?> 件</p>
<?php while (have_posts()) : the_post(); ?>
—ループ—
<?php endwhile; ?>
■結果:

【追記】
wordpress 2.0系での記事件数表示
■カテゴリページ
$counter = new WP_Query(”posts_per_page=-1&cat=$cat”);
echo count($counter->posts) .” 件”;
echo count($counter->posts) .” 件”;
※posts_per_page=-1を指定してあげないと、ページ分割された後の数が表示されてしまう(たとえば10件など)
■トップページ(全件)
$counter = new WP_Query(”showposts=-1“);
echo $counter->post_count .” 件”;
echo $counter->post_count .” 件”;
■検索結果
$s_word = wp_specialchars($s,1);
$counter = new WP_Query(”posts_per_page=-1&s=$s_word“);
echo count($counter->posts) .” 件”;
$counter = new WP_Query(”posts_per_page=-1&s=$s_word“);
echo count($counter->posts) .” 件”;
以上
コメント/質問お待ちしています