2017-03-15 4 views
0

どのように私は、このページhttp://greyenlightenment.com/real-estate-palo-alto-vs-everywhere-else/シンプルなFacebookの+ Twitterのワードプレスのシェアボタン

上のもののように見えるし、同様に共有カウンタを持っているFacebookのシェアボタンを得るのですか?私は一日以上無駄な共有ボタンを探して過ごしました。ほとんどのボタンは大きすぎるか、Facebookの共有数を数えません。現在のページと現在のページのタイトルのリンクを取得WordPressの機能をget_permalink()とget_the_title()されています

注:誰かが私にボタンのこの

答えて

0

を行うことができ、簡単なPHPスクリプトを見つけることができますが、このコードが必要です。カウント共有ページについては

.share-button { 
 
    font-family: sans-serif; 
 
    display: inline-block; 
 
    padding: 7px 10px; 
 
    border: 1px solid #EEE; 
 
    border-radius: 3px; 
 
    background-color: #FAFAFA; 
 
    color: #656565; 
 
    text-decoration: none; 
 
} 
 

 
.share-button:hover { 
 
    border: 1px solid #999; 
 
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1); 
 
} 
 

 
.share-button span { 
 
    display: inline-block; 
 
    margin-right: 10px; 
 
    color: red; 
 
}
<a class="share-button" href="http://www.facebook.com/sharer/sharer.php?u=<?php echo get_permalink();?>&amp;t=<?=urlencode(get_the_title());?>" target="_blank"><span id="share-facebook">0</span>Facebook</a> 
 

 
<a class="share-button" href="http://www.twitter.com/intent/tweet?url=<?php echo get_permalink();?>&amp;text=<?=urlencode(get_the_title());?>" target="_blank"><span id="share-twitter">0</span>Twitter</a> 
 

 
<a class="share-button" href="http://plus.google.com/share?url=<?php echo get_permalink();?>" target="_blank"><span id="share-gplus">0</span>Google Plus</a>

、あなたは#シェア-のFacebookなどのように、APIキーを必要とし、それぞれにリターンを挿入...この議論Getting the Facebook like/share count for a given URL

上の共有を取得する方法の詳細を参照してください

APIキーをお持ちの場合は、要求を出して共有ページ番号を取得し、情報を持つオブジェクトを取得した後、divに追加します。

<script type="text/javascript"> 
    facebookreturnobject = $.getJSON('https://graph.facebook.c...'); // see examples on discussion above 
    $('#share-facebook').text(facebookreturnobject.share.count); 
</script> 

TwitterとGoogle Plusで同じことをします。

+0

コードでアクセストークンを公開する必要があるため、現在の数をJS経由でクライアント側で行う必要はありません。したがって、ユーザーがサイトにログインしてユーザーアクセストークンを使用できるようにしない限り、これはサーバー側で行う必要があります。さらに、すべてのページの読み込み時に実行するべきではありません。速度の制限をかなり早く乗り越えることができます。したがって、キャッシュのいくつかの形式も同様に実装する必要があります。 – CBroe

0

ボタンを共有するためのプラグインは多数あります。あなたはちょうど1つを選択する必要があります。 link to the official wordpress site

関連する問題