【问题标题】:Change existing javascript Ticker to work from RSS feed更改现有的 javascript Ticker 以从 RSS 提要工作
【发布时间】:2014-05-13 22:03:35
【问题描述】:

我不擅长编写代码,所以可能会在任何可能提供帮助的人手中。

我在我的 wordpress 网站 www.solosails.com 上有一个正常工作的 Ticker Tape

目前,它适用于手动输入的数据,我想对其进行修改,以便它从我的 RSS 提要 myurl/提要中获取标题和链接,希望通过使用类似这样的东西...

$.get(FEED_URL, function (data) {
$(data).find("entry").each(function () { // or "item" or whatever suits your feed
    var el = $(this);

    console.log("------------------------");
    console.log("title      : " + el.find("title").text());
    console.log("author     : " + el.find("author").text());
    console.log("description: " + el.find("description").text());
});

});

Java Script 代码是...

function startTicker(){theCurrentStory=-1;theCurrentLength=0;if(document.getElementById){theAnchorObject=document.getElementById("tickerAnchor");runTheTicker()}else{document.write("Error");return true}}function runTheTicker(){var e;if(theCurrentLength==0){theCurrentStory++;theCurrentStory=theCurrentStory%theItemCount;theStorySummary=theSummaries[theCurrentStory];theTargetLink=theSiteLinks[theCurrentStory];theAnchorObject.href=theTargetLink}theAnchorObject.innerHTML=theStorySummary.substring(0,theCurrentLength)+whatWidget();if(theCurrentLength!=theStorySummary.length){theCurrentLength++;e=theCharacterTimeout}else{theCurrentLength=0;e=theStoryTimeout}setTimeout("runTheTicker()",e)}function whatWidget(){if(theCurrentLength%2==1){return theWidgetOne}else{return theWidgetNone}}

这是可能需要更改的代码部分,以便硬编码的链接和标题成为从 rss 提要中提取的新代码...

var theCharacterTimeout = 50;
var theStoryTimeout     = 4000;
var theWidgetOne        = "_";
var theWidgetNone       = "";

var theSummaries = new Array();
var theSiteLinks = new Array();

var theItemCount = 2;

theSummaries[0] = "Solo Sails proudly sponsor Lizzy Foremans Mini Transat Campaign...       Read more here ...";
theSiteLinks[0] = "http://www.solosails.com/solo-sails-sponsor-lizzie-foremans-mini-transat-campaign/"

theSummaries[1] = "10% discounts on ALL multiple sail orders !! Try us for price with your new sails, complete our simple quote form here.";
theSiteLinks[1] = "http://www.solosails.com/quotes"

startTicker();

如果您能提供帮助,请提前非常感谢!

安德鲁

【问题讨论】:

    标签: javascript wordpress parsing rss


    【解决方案1】:

    仍然希望有人可以在这里提供帮助。

    我基本上想要从 rss 中获取 theSummaries 和 theSiteLinks,或者更改数组以便它们在 Javascript 中使用 XML 解析器。

    非常感谢这里的一些帮助,并很高兴通过贝宝为工作结果捐赠一些东西。

    问候,安德鲁

    【讨论】:

      【解决方案2】:

      感谢@David Hammond 找到答案...

      var theCharacterTimeout = 75;
      var theStoryTimeout     = 4000;
      var theWidgetOne        = "_";
      var theWidgetNone       = "";
      
      var theSummaries = new Array();
      var theSiteLinks = new Array();
      
      jQuery.get('http://www.solosails.com/feed/', function(data) {
      var $xml = jQuery(data);
      $xml.find("item").each(function() {
          var $this = jQuery(this),
              item = {
                  title: $this.find("title").text(),
                  link: $this.find("link").text()
          }
          //Do something with item here...
          theSummaries.push(item.title);
          theSiteLinks.push(item.link);
      });
      theItemCount = theSummaries.length;
      startTicker();
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多