"Bu Sayfayı Paylaş"- widget'ını, şu anki URL'yi kapmak/ ve bunun gibi bir Facebook URL'sine eklemek için) yaratıyorum
http://www.facebook.com/sharer.php?u=http://myurl.com/a-specific-page
Normal bir metin widget'ı kullanıyorum. Geçerli URL’ye nasıl erişebilir ve onu paylaşım bağlantısına nasıl ekleyebilirim?
@ user653 doğru, PHP içeren bir metin widget'ında bunu yapamazsınız, ancak JQuery / Javascript kullanarak bir metin widget'ında bunu yapabilirsiniz. . İşte nasıl.
Facebook Paylaş Düğmesi 'yi kullanmayı planladığınızı ve böylelikle widget'ınızda bu şekilde görünecek HTML kodunu içereceğini tahmin ediyorum.
<a name="fb_share"></a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share"
type="text/javascript">
</script>
Javascript's windows.location
object.property öğesini kullanınEğer evet ise, o zaman widgetınıza sadece aşağıdaki kodların tamamını ekleyin:
<script type="text/javascript">
jQuery(document).ready(function($) {
$("fb_share").attr("share_url") = encodeURIComponent(window.location);
});
</script>
<a name="fb_share"></a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript">
</script>
functions.php
Dosyasında jQuery'yi Enqueue ettiğinizden emin olunBununla birlikte, yukarıdaki kodun çalışması için muhtemelen WordPress ile birlikte gelen jQuery betiğini sıkmanız gerekecek (ayrıca başka bir eklenti zaten yapmadıkça) aşağıdaki kod satırını temanızın functions.php
'suna ekleyin:
wp_enqueue_script('jquery');
İronik olarak, bir müşteri için bir kaç gün önce Facebook Like ButtonKısa Kod / bir uygulama yaptım, bu yüzden ben de paylaşmalıyım ;) Şu anki URL’yi $_SERVER
değişkeninden nasıl aldığımızı görebilirsiniz. Bu tam kodu /wp-includes/canonical.php'
içindeki redirect_canonical()
işlevinden aldım. Bunu temanızın functions.php
dosyasına da ekleyebilirsiniz:
add_shortcode('facebook-like','my_facebook_like_button');
function my_facebook_like_button($echo=true) {
// Generate the HTML required to place a Facebook "Like" button inside a shortcode
// See Docs: http://developers.facebook.com/docs/reference/plugins/like
$requested_url = is_ssl() ? 'https://' : 'http://';
$requested_url .= $_SERVER['HTTP_Host'];
$requested_url .= $_SERVER['REQUEST_URI'];
$html =<<<HTML
<iframe src="http://www.facebook.com/plugins/like.php?href={$requested_url}&layout=button_count&show_faces=false&width=60&action=like&font=verdana&colorscheme=light&height=21&ref=blog"
scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:90px; height:25px"></iframe>
HTML;
if ($echo)
echo $html;
else
return $html;
}
İşte kullanımını gösteren bir ekran görüntüsü. Metin widget'ları içerik filtrelerini işlemediğinden bu nedenle kısa kodun bir metin widget'ında çalışmadığını unutmayın. Çabucak baktım ve kısa kodları işleyebilen metin widget'ları ekleyen bir eklenti bulamadım, ancak bir tane yazmak zor değildi, ya da sadece bir Facebook Paylaşımı veya Beğen düğmesi ekleyen bir widget yazmak zor değildi. FWIW.
Bu yardımcı olur umarım!
Sadece $ _SERVER değişkenlerini kullanın:
$url = add_query_arg( 'u', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"], 'http://www.facebook.com/sharer.php' );
Bir metin widget'ının içeriğini bu şekilde dinamik hale getiremezsiniz. Örneğin "Yürütülebilir PHP widget" (http://wordpress.org/extend/plugins/php-code-widget/) edinin. Şimdi değişken URL'sini eklemek için php kodu içeren metninizi vb ekleyebilirsiniz.
[değiştir] Ref http://developers.facebook.com/docs/reference/plugins/like . Bunu php kodunuza widget'ı ekleyin:
<?php global $post; ?>
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&layout=standard&show_faces=false&width=450&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>
İşte sizin için bazı tam kod:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<a href="http://Twitter.com/share" class="Twitter-share-button" data-url="" data-count="vertical" data-via="arkliapp">Tweet</a>
<script type="text/javascript" src="http://platform.Twitter.com/widgets.js"></script>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like id="fb_like" href="" layout="box_count" show_faces="true" width="55" font=""></fb:like>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#fb_like").attr("href") = encodeURIComponent(window.location);
$(".Twitter-share-button").attr("data-url") = encodeURLComponent(window.location);
});
</script>