<---------------------------- ----------------------------> <---------------------------- ----------------------------> --------------------> WordPress プラグイン Social Metrics に “はてなブックマーク” を追加した – Inside of Papaya

WordPress プラグイン Social Metrics に “はてなブックマーク” を追加した

ブログのページに置かれているソーシャル系のボタン。
これがどれくらい押されているのかがひと目わかるプラグインがあります。

Social Metrics

我が家はまだかなり寂しい状況ですが、将来的にもこれはあってもいいかなと思って入れているプラグインです。

一画面で記事ごとのツイート数や、いいね!数が眺められてとてもいいのですが、日本にいる以上、”はてなブックマーク” は外せないかもと思い、少々ソースを弄くることにしました。

デフォルトで出ているのは

  • Twitter
  • Facebook
  • Google+1
  • StumbleUpon
  • Digg
  • LinkedIn

なんですけど、”StumbleUpon” はよくわかんないから外して、代わりに “はてブ” を入れます。

はてブのボタンは、こちらのサイトで作れます。

hatena_bookmark_button

↑こんな感じで。
でき上がったコードはこんな感じ↓。

[php]
<a href="http://b.hatena.ne.jp/entry/http://insideofpapaya.com" class="hatena-bookmark-button" data-hatena-bookmark-layout="standard-balloon" title="このエントリーをはてなブックマークに追加"><img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" /></a><script type="text/javascript" src="http://b.st-hatena.com/js/bookmark_button.js" charset="utf-8" async="async"></script>
[/php]

href 部分は記事ごとのパーマリンクを持ってこないと。

[php]
<a href="http://b.hatena.ne.jp/entry/<?php the_permalink() ?>" class="hatena-bookmark-button" data-hatena-bookmark-layout="standard-balloon" title="このエントリーをはてなブックマークに追加"><img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" /></a><script type="text/javascript" src="http://b.st-hatena.com/js/bookmark_button.js" charset="utf-8" async="async"></script>
[/php]

では、ソースを弄ってみます。
触るファイルは wp-content/plugins/social-metrics/socialmetrics.php です。
基本、”StumbleUpon” の部分を “Hatena” に換えて、上のコードに入れ換えれば OK!
該当部分はこんな感じです↓。

[php highlight=”8,20,32″]
<table class="widefat post fixed smtable" cellspacing="0">
<thead>
<tr>
<th scope="col" id="title0" class="manage-column column-title" >Title</th>
<th scope="col" id="title1" class="manage-column column-title" >Twitter</th>
<th scope="col" id="title2" class="manage-column column-title" >Facebook</th>
<th scope="col" id="title3" class="manage-column column-title" >Google +1</th>
<th scope="col" id="title4" class="manage-column column-title" >Hatena</th>
<th scope="col" id="title5" class="manage-column column-title" >Digg</th>
<th scope="col" id="title6" class="manage-column column-title" >LinkedIn</th>
</tr>
</thead>
<tbody>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<tr>
<td ><a href="<?php the_permalink() ?>" target="_blank" rel="bookmark"><?php the_title(); ?></a></td>
<td ><a href="http://twitter.com/share" class="twitter-share-button" data-text="<?php the_title(); ?>" data-count="horizontal" data-url="<?php the_permalink() ?>">Tweet</a></td>
<td ><iframe src="http://www.facebook.com/plugins/like.php?href=<?php the_permalink(); ?>&send=false&layout=button_count&width=100&show_faces=false&action=like&colorscheme=light" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe></td>
<td ><g:plusone size="medium" href="<?php the_permalink(); ?>"></g:plusone></td>
<td ><a href="http://b.hatena.ne.jp/entry/<?php the_permalink() ?>" class="hatena-bookmark-button" data-hatena-bookmark-title="Inside of Papaya" data-hatena-bookmark-layout="standard-balloon" title="このエントリーをはてなブックマークに追加"><img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" /></a><script type="text/javascript" src="http://b.st-hatena.com/js/bookmark_button.js" charset="utf-8" async="async"></script></td>
<td ><a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>"></a></td>
<td ><script type="in/share" data-url="<?php the_permalink(); ?>" data-counter="right"></script></td>
</tr>
<?php endwhile; ?>
</tbody>
<tfoot>
<tr>
<th scope="col" class="manage-column column-title" >Title</th>
<th scope="col" class="manage-column column-title" >Twitter</th>
<th scope="col" class="manage-column column-title" >Facebook</th>
<th scope="col" class="manage-column column-title" >Google +1</th>
<th scope="col" class="manage-column column-title" >Hatena</th>
<th scope="col" class="manage-column column-title" >Digg</th>
<th scope="col" class="manage-column column-title" >LinkedIn</th>
</tr>
</tfoot>

</table>
[/php]

これで OK!
結果を見てみましょう。

SocialMetrics_modified

いいっすね。

以上、簡単なモディファイでした。

※こちらのサイトを参考にさせていただきました → 『ブログ記事のTweet数やブクマ、いいね!の数を管理画面に一覧表示するWordPressプラグイン・Social Metricsを日本向けにした


Fatal error: Uncaught Error: Call to undefined function related_posts() in /home/insidepapaya/insideofpapaya.com/public_html/wordpress/wp-content/themes/hueman-child/single.php:71 Stack trace: #0 /home/insidepapaya/insideofpapaya.com/public_html/wordpress/wp-includes/template-loader.php(106): include() #1 /home/insidepapaya/insideofpapaya.com/public_html/wordpress/wp-blog-header.php(19): require_once('/home/insidepap...') #2 /home/insidepapaya/insideofpapaya.com/public_html/index.php(17): require('/home/insidepap...') #3 {main} thrown in /home/insidepapaya/insideofpapaya.com/public_html/wordpress/wp-content/themes/hueman-child/single.php on line 71