Skip to content

Instantly share code, notes, and snippets.

@matthiaspabst
Created December 27, 2011 17:37
Show Gist options
  • Save matthiaspabst/1524502 to your computer and use it in GitHub Desktop.
Save matthiaspabst/1524502 to your computer and use it in GitHub Desktop.
Teilen-Buttons für Twitter und Facebook per jQuery erst nach dem Inhalt laden
<!-- Sharebuttons erst nach Content laden -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var facebook_links = new Array();
var twitter_links = new Array();
</script>
<script type="text/javascript">
$(function(){
$(window).bind("load", function(){
$(".sharebuttons").each(function(index){
var sb = $(this);
$.get('<?php bloginfo('stylesheet_directory'); ?>/ajax.php', {
fb: facebook_links[index],
tw: twitter_links[index]
}, function(data){
$(sb).append(data);
});
});
});
})
</script>
<!-- Ende: Sharebuttons erst nach Content laden -->
<div class="sharebuttons">
<script type="text/javascript">
facebook_links.push('http://www.facebook.com/plugins/like.php?href=<?php the_permalink(); ?>&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=21');
twitter_links.push('http://platform.twitter.com/widgets/tweet_button.html?url=<?php the_permalink(); ?>&amp;text=<?php the_title(); ?>&amp;count=horizontal&amp;lang=de&amp;via=dein-twitter-name');
</script>
</div><!-- .sharebuttons" -->
<div class="twitter"><iframe class="twitter-share-button twitter-count-horizontal" src="<?php echo $_GET['tw']; ?>" style="width:120px; height:20px;" allowtransparency="true" frameborder="0" scrolling="no" title="Diesen Artikel twittern"></iframe></div>
<div class="facebook"><iframe src="<?php echo $_GET['fb']; ?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe></div>
*Sharebuttons*/
.sharebuttons { clear: both; margin: 10px 0; }
.sharebuttons .twitter { float: left; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment