はてなブックマーク件数取得APIに新しいAPIが追加されたらしいので試してみた。

テーマの index.php とか single.php などの表示したい所に以下のコードを挿入する。

<a href="http://b.hatena.ne.jp/entry/<?php the_permalink() ?>">
<script type="text/javascript" src="http://api.b.st-hatena.com/entry.count?url=<?php the_permalink() ?>&amp;callback=document.write"></script> users
</a>

見た目にこだわりたい場合

はてなブックマークのような見た目にしたい場合は、strong タグをつけて、CSS を追加。

テーマのPHPファイルに追加

<strong class="hb_users">
<a href="http://b.hatena.ne.jp/entry/<?php the_permalink() ?>">
<script type="text/javascript" src="http://api.b.st-hatena.com/entry.count?url=<?php the_permalink() ?>&amp;callback=document.write"></script> users
</a>
</strong>

スタイルシートに追加

strong.hb_users a:link,
strong.hb_users a:hover,
strong.hb_users a:visited {
  color: #F00 !important;
  background: #FCC !important;
}

参照

(開発者さま向け)はてなブックマーク件数取得APIに新しいAPIを追加 – はてなブックマーク日記 – 機能変更、お知らせなど
新はてなブックマーク件数取得 API を使って自分のページに件数を埋め込む最も簡単な方法 – IT戦記

トラックバック一覧

  1. […] Shared WordPress の個別記事にブックマーク件数を埋め込む : zontheworld. […]

    ピンバック:今週の気になるアレOctober 8th | 2009/10/08 木曜日 17:17

  2. […] こことここを見てたら設置してみたくなったのでメモ。 テーマのindex.phpとかsingle.phpなどの表示したい所に以下のコードを挿入する。 […]

    ピンバック:はてなブックマーク件数をAPIで埋め込んでみる « www.undakovr.com | 2009/11/25 水曜日 12:59

コメント一覧

この記事にはコメントがついていません。

RSS feed for comments on this post.

コメント投稿

Sorry, the comment form is closed at this time.