dsunj08246 2012-04-18 15:25
浏览 32
已采纳

社交图标不使用Wordpress上的无限滚动

We are making a website for a client at work, which can be found here: http://ethercreative.net/studio_social/ It's a very simple wordpress theme, but the complications are arising with conflicts between the infinite scrolling plugin, and the social icons.

Each post is meant to display a block at the end with G+, FB and Twitter social icons inside. It is meant to display ~4 posts or so at start, and then as you scroll it is meant to load the next set.

Each of these things work, but not together.

When the infinite scroll loads the next block of posts, it only shows a facebook like button, and neither of the other two social icons.

The strange thing is though, it leaves behind blocks of the code:

<span class="icons">
                    <g:plusone size="medium" href="http://ethercreative.net/studio_social/?p=1"></g:plusone>                <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fethercreative.net%2Fstudio_social%2F%3Fp%3D1&amp;locale=&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:92px; height:20px;" allowtransparency="true"></iframe>&nbsp;&nbsp;&nbsp;
                    <a href="http://twitter.com/share" class="twitter-share-button" data-url="http://ethercreative.net/studio_social/?p=1" data-count="horizontal" data-text="Hello world!" data-via="twitter_username"></a></span>
</div>

I know what the issue is and why it's happening, but I'm really not very good with javascript and do not know what calls to use to fix it.

I am using Wordpress 3.3.1, with the infinite scroll plugin (http://wordpress.org/extend/plugins/infinite-scroll/) and digg digg for the social icons (http://wordpress.org/extend/plugins/digg-digg/)

The infinite scroll plugin does have the ability to add onLoad events to run after it has grabbed the new set of posts. So what should I add here?

Thanks for any and all help in advance! Have a nice day.


Update: After some more research, I have fixed twitter too. Now it is just Google Plus left to fix. The code required for twitter was:

!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");

Update again: Found the Google Plus code too:

(function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })();

What have I learnt? Do more googling before asking on Stack Overflow. At least heres the answer for people with this issue in future.

  • 写回答

3条回答 默认 最新

  • dplo59755 2012-05-05 02:03
    关注

    The solution you presented basically is reloading the scripts, which is pretty inefficient, since you likely loaded them on page load for the first set of social buttons. All 3 of the services have a way to parse a section of the, or the entire, document to render any new social widgets. The code you want would be something like this:

    var el = document.body; 
    
    //Google Plus   
    if (typeof gapi !== "undefined") { gapi.plusone.go(el); }
    
    //Facebook
    if (typeof FB !== "undefined") { FB.XFBML.parse(el); }
    
    //Twitter
    if (typeof twttr !== "undefined") { twttr.widgets.load(); }
    

    In the above cases, el should be the container that holds the widgets or can probably just be document.body (would re-render all widgets.) Not sure if you can narrow the context with Twitter currently, but I believe they plan to add that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型