改变现有的javascript Ticker工作从RSS提要

Change existing javascript Ticker to work from RSS feed

本文关键字:工作 RSS 提要 Ticker javascript 改变      更新时间:2023-09-26

我不擅长写代码,所以我有点需要别人的帮助。

我有一个功能正常的Ticker Tape工作在我的wordpress网站这里www.solosails.com

目前,它的工作从数据手动输入,我想修改它,使它采取的标题和链接从我的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();

如果你能帮忙,提前感谢!

安德鲁

还是希望有人能帮忙。

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

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

问候,安德鲁。

感谢@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();
});