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でTwitterのフォロワー数などを表示する方法

我々は以前にRarstによって寄稿されたTwitterのフォロワー数を表示することができますコードについて書いている。この投稿では、WordPressでTwitterのフォロワー数を表示できる、より高度でエレガントなコードを紹介します。再びこのスクリプトもRarstによって寄稿された。

機能

この関数はフォロワー数に限定されません。Twitter users/show APIメソッドによって返されるネストされていない値を取得することができます。

2段階のキャッシュがあります:

  • クエリーされた値は、WPオプションを使用してデータベースに配列として$interval秒間保存されます;
  • APIレスポンスはメモリに保存されるので、何度もAPIリクエストを発生させることなく、いくつでもフィールドをクエリーできます。

APIレスポンスはメモリに保存されるので、APIリクエストを何回も発生させることなく、いくつでもフィールドに問い合わせることができます。これは、APIの制限を使い果たすことを心配することなく、同時に複数の値や複数のユーザーに対して安全に使用できるはずです。

チュートリアル

まずテーマのfunctions.phpファイルを開き、以下のコードを追加します:

[cbk1]

使い方

この関数を貼り付けたら、あとはWordPressのテンプレート・ファイルに貼り付けるだけです。以下のコードを貼り付けるだけです:

[cbk2]

上記のコードはこのように表示されます:

WPBeginnerは1300回の更新で5846人のフォロワーを獲得しました。

ソースRarst

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

アバター

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

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

  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!

  2. Aleks says

    Someone explain where I put in my own twitter username please? Cause I really cant see where… And I cant get it to work either… No matter what.. This just wont give me username, not even leaving it completly basic as it stands right now, I get no response on username what so ever… it just displays: “has followers after updates”…
     
    That’s it.. nothing else…

  3. Downhill_MC says

    this is a great code. i wonder if there is a possibility to create a function for embedding in text (something like ). downhill_mc

  4. Rarst says

    Glad you found it useful. :) Old snippet still works but it got kinda outdated and spread around a lot – it was getting hard to answer questions and correct outdated parts all the time.

    This one is slightly more bulky, but it has much extended functionality for showing more data and for different usernames at the same time.

    I also intend to maintain it more properly so feedback and suggestions are welcome on its page at my blog.

返信を残す

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