Advertisement
Guest User

Wordpress : Custom facebook share buttons

a guest
Dec 5th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. HEADER:
  2. <script>
  3. window.fbAsyncInit = function(){
  4. FB.init({
  5.     appId: 'mojAppID', status: true, cookie: true, xfbml: true });
  6. };
  7. (function(d, debug){var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
  8.     if(d.getElementById(id)) {return;}
  9.     js = d.createElement('script'); js.id = id;
  10.     js.async = true;js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
  11.     ref.parentNode.insertBefore(js, ref);}(document, /*debug*/ false));
  12. function postToFeed(title, desc, url, image){
  13. var obj = {method: 'feed',link: url, picture: 'http://www.url.com/images/'+image,name: title,description: desc};
  14. function callback(response){}
  15. FB.ui(obj, callback);
  16. }
  17. </script>
  18.  
  19. INDEX.PHP
  20. Loop početak-->
  21. <?php
  22.     $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
  23.     $url = $thumb['0'];
  24. ?>
  25.  
  26. <a href="<?php the_permalink('');?>" data-image="<?php the_post_thumbnail(''); ?>" data-title="<?php the_title();?>" data-desc="<?php the_excerpt();?>" class="btnShare">Share</a>
  27.  
  28. FOOTER:
  29. <script>
  30.     $('.btnShare').click(function(){
  31.     elem = $(this);
  32.     postToFeed(elem.data('title'), elem.data('desc'), elem.prop('href'), elem.data('image'));
  33.  
  34.     return false;
  35.     });
  36. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement