Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressで投稿の総数を表示する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressサイトの投稿総数を表示しますか?

投稿記事の総数を表示することで、ブログの一貫性をアピールし、ユーザーがより多くのコンテンツを探すことを促すことができる。

この投稿では、WordPressで投稿の総数を簡単に表示する方法を紹介する。

Show total number of posts in WordPress

なぜWordPressで投稿総数を表示するのか?

多くの記事を公開している場合、WordPressで投稿の総数を表示することは、社会的証明を表示する素晴らしい方法です。

サイト訪問者に、新しいコンテンツをコンスタントに公開していることや、書いているトピックについて多くの経験を持っていることを示すことができます。これにより、訪問者の信頼を高め、忠実な読者や購読者になってもらうことができる。

投稿の総数を表示することで、訪問者がサイトに長く滞在することもできます。他にもたくさんの投稿があることを知れば、訪問者はより長く滞在し、それらをチェックする可能性が高くなる。

ということで、WordPressで投稿の総数を表示する2つの異なる方法を紹介します。以下のクイックリンクから、使いたい方法にすぐにジャンプできます。

方法1:プラグインを使ってWordPressの投稿総数を表示する

この方法は簡単で、すべてのユーザーにお勧めできる。

まず最初に、Simple Blog Statsプラグインをインストールして有効化します。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

有効化した後、Settings ” Simple Blog Statsでプラグインの設定を行う必要があります。

Simple Blog Statsプラグインは、コメント数、ユーザー数、ページ数、投稿数などのWordPressの便利な統計情報を表示します。WordPressサイト上の任意の場所にショートコードを使用して簡単にこれらの統計情報を表示することができます。

Blog stats shortcodes

sbs_posts]ショートコードをコピーして、WordPressの投稿、ページ、ショートコード有効化のサイドバーウィジェットに追加するだけです。

WordPressサイトで公開されている投稿の総数が表示されます。

number of posts

また、[sbs_blog_stats]を使えば、投稿数を含むすべてのブログの統計情報を表示することができます。

Blog stats

方法2.WordPressで投稿の総数を手動で表示する

この方法では、WordPressサイトにコードを追加する必要があります。WordPressでコードをコピー&ペーストする方法をご覧ください。

まず、テーマのfunctions.phpファイルまたはコード・スニペット・プラグインにこのコードを追加する必要があります。

function wpb_total_posts() { 
$total = wp_count_posts()->publish;
echo 'Total Posts: ' . $total;
} 

このコードは、テンプレートタグwpb_total_postsが呼び出されるたびに、単純に投稿の総数を出力します。

WordPressでこのコードを追加する最も簡単な方法は、WPCodeのようなコードスニペットプラグインを使用することです。テーマのfunctions.phpファイルを編集することなく、安全にコードを追加することができるので、サイトを壊す心配がありません。

開始するには、無料のWPCodeプラグインをインストールし、有効化する必要があります。ヘルプが必要な場合は、WordPressプラグインのインストール方法のチュートリアルに従ってください。

プラグインを有効化したら、WordPressダッシュボードからCode Snippets + Add Snippetにアクセスします。Add Snippetページで、「Add Your Custom Code (New Snippet)」オプションを見つけ、その下の「Use snippet」ボタンをクリックします。

Add a new custom code snippet in WPCode

次に、スニペットのタイトルを追加し、上記のコードを「コードプレビュー」ボックスに貼り付けます。右側のドロップダウンリストから、コードタイプとして「PHPスニペット」を選択することも忘れないでください。

Paste code into the WPCode plugin and select the code type

その後、スイッチを’Inactive’から’Active’に切り替え、’Save Snippet’ボタンをクリックするだけです。

Activate and save your custom code snippet

それが完了したら、投稿の合計数を表示したい場所に<?php wpb_total_posts(); ?>を追加する必要があります。

テンプレートタグを使いたくない場合は、まったく同じことをするショートコードを作って使うことができる。

以下のコードをテーマのfunctions.phpファイルまたはコードスニペットプラグインにコピー&ペーストしてショートコードを作成します:

function wpb_total_posts() { 
$total = wp_count_posts()->publish;
return $total; 
} 
add_shortcode('total_posts','wpb_total_posts');

上記と同じ手順で、WPCodeプラグインを使って簡単にこのコードを追加することができます。

Paste code in the WPCode plugin to create shortcode

このショートコード [total_posts]を使って、投稿、ページ、サイドバーウィジェットに投稿の総数を表示できるようになりました。

この投稿が、WordPressで投稿の総数を表示する方法を学ぶのにお役に立てば幸いです。WordPressのTips、トリック、ハックのメガリストや、WordPressの関連投稿プラグインもご覧ください。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

16件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

    • WPBeginner Support says

      We’ll be sure to take a look at our code, for the time being, you may want to look into the plugin for an alternative :)

      管理者

    • WPBeginner Support says

      For the plugin, you would want to reach out to the plugin’s support for if that is an option in the current version.

      管理者

  2. Itisme64 says

    Hi Nice and works great with the shortcode. Tried plugin and stopped the website.

    How do i get separate like 21.500 posts ? now it say 21500

    cheers

    • WPBeginner Support says

      Using the shortcode method in your functions.php or your site-specific plugin you would replace:
      return $total;
      With:
      return number_format_i18n($total);
      to add the comma

      管理者

  3. jay says

    Thanks for the extremely useful article (for us non-programmers). What if I have 6 different categories of posts (related to, say, jobs, offices for rent, supplies, etc.), and I want to get a separate count for each category?

    • WPBeginner Support says

      Hi Jay,

      If you just want to show how many posts are there in each category then you can use the Categories widget and add it to your sidebar. In widget settings you will see an option to display the number of posts next to each category.

      管理者

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。