简体   繁体   English

Twitter 在常规 div 中输入?

[英]Twitter feed in a regular div?

Twitter's embed code is a big clunky if you ask me.如果你问我,Twitter 的嵌入代码非常笨重。 It appears you have to load the js and put the js embed code (javascript) in the page where you want it in order for it to show up.看来您必须加载 js 并将 js 嵌入代码(javascript)放在您想要它的页面中才能显示出来。 I would like to load the js right before the end of my </body> and also put the js script in there as well.我想在我的</body>结束之前加载 js,并将 js 脚本也放在那里。 I would then like to just place an empty div anywhere on my page and the twitter feed will display there.然后,我想在页面的任何位置放置一个空 div,twitter 提要将显示在那里。 Like <div id='twitter_feed'></div> Is that possible adjusting the code that Twitter gives us?<div id='twitter_feed'></div>这样可以调整 Twitter 给我们的代码吗?

<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 4,
  interval: 6000,
  width: 250,
  height: 300,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#4aed05'
    }
  },
  features: {
    scrollbar: true,
    loop: false,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('example').start();
</script>

My question is not how to using different tools to render a feed.我的问题不是如何使用不同的工具来呈现提要。 My question is how do I make the above code that twitter provides and write it in a way that it will render in a div that I specify.我的问题是如何制作 twitter 提供的上述代码,并以一种将呈现在我指定的 div 中的方式编写它。

After reading though this...http://www.dustindiaz.com/twitter-widget-doc I found that you can specify an id.读完这篇... http://www.dustindiaz.com/twitter-widget-doc 我发现你可以指定一个ID。

This sounds like what you want, using jQuery tweets plugin found on http://plugins.jquery.com/project/jQuery-Tweets听起来像你想要的,使用http://plugins.jquery.com/project/jQuery-Tweets上的 jQuery 推文插件

HTML HTML

<div id="tweets">
</div>

jQuery jQuery

 $('#tweets').tweets({
           tweets:4,
           username: "jquery"
  });

or using your current widget http://jsfiddle.net/mazlix/dZ2aP/或使用您当前的小部件http://jsfiddle.net/mazlix/dZ2aP/

<div class="content_up_here">
There's so much stuff here.
</div>
<script>twitterwidget();</script>
<div class="content_down_here">
Lorem and Ipsum sitting in a tree. D O L O R S I T.
</div>
var username = "username";
$.getJSON("http://twitter.com/statuses/user_timeline/"+username+".json?callback=?",
function(data) {  
  function replaceURLWithHTMLLinks(text) {
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(exp,"<a href='$1'>$1</a>"); 
  }

  $("#tweet").html(replaceURLWithHTMLLinks(data[0].text));
});

The above script will parse links and usernames and make them actual links.上面的脚本将解析链接和用户名并使它们成为实际链接。 All you need to do is have a div with the id of #tweet .您需要做的就是拥有一个 id 为#tweet的 div。 Make sure you load jQuery too.确保也加载 jQuery。 This also get only one lastest tweet.这也只会获得一条最新的推文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM