Domanda

I am not good at code so am a bit in the hands of anyone who might be able to help.

I have a functioning Ticker Tape working in my wordpress site here www.solosails.com

currently, it works from data manually entered, I would like to modify it so that it takes the title and link from my RSS feed myurl/feed hopefully by using something like this ...

$.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());
});

});

The Java Script code is...

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}}

This is the part of the code that potentially needs altering so that the hardcoded links and titles become the new code pulling from the rss feed...

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();

Many thanks in advance if you can help!

Andrew

È stato utile?

Soluzione 2

Thanks to @David Hammond for finding the answer ...

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

Altri suggerimenti

Still hoping somebody can help here.

I basically want to either get theSummaries and theSiteLinks to be pulled from the rss or change the arrays so that they use the XML parser in Javascript.

Would really appreciate some help here and happy to donate something via paypal for the working result.

Regards, Andrew

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top