...

View Full Version : RSS Ajax JavaScript ticker - Limiting the number of posts displayed?



ehartnett00
02-08-2007, 05:07 PM
Hello.

I'm using the RSS Ajax JavaScript ticker (http://www.javascriptkit.com/dhtmltutors/ajaxticker/index.shtml) but I cannot seem to figure out how to limit the number of posts that are displayed. I have created a news blog for my library and am using the ticker to display the news on our library website (http://unicorn.ntcc.edu). The default seems to be set to display all of the posts. I would prefer to limit it to only the last 4 or 5.

Does anybody know how to do this?

Thanks.

shyam
02-09-2007, 04:18 PM
this should do the job i guess

somewhere in rssticker.js do this


//Cycle through RSS XML object and store each piece of the item element as an attribute of the element
var maxItems = this.feeditems.length <= 5 ? this.feeditems.length : 5;
for (var i=0; i<maxItems; i++){
this.feeditems[i].setAttribute("ctitle", this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue)
this.feeditems[i].setAttribute("clink", this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue)
this.feeditems[i].setAttribute("cdescription", this.feeditems[i].getElementsByTagName("description")[0].firstChild.nodeValue)
}

ehartnett00
02-20-2007, 02:51 PM
this should do the job i guess

somewhere in rssticker.js do this



Thanks for the help. I tried your suggested changes and it does limit the number of posts that are displayed to 5 but the 5 posts no longer continually cycle - once the 5th post displays, the ticker stops on that post.

I must be missing something but I don't see why this is happening.

Any ideas?

FJbrian
02-20-2007, 03:20 PM
this should do the job i guess

somewhere in rssticker.js do this


//Cycle through RSS XML object and store each piece of the item element as an attribute of the element
var maxItems = this.feeditems.length <= 5 ? this.feeditems.length : 5;
for (var i=0; i<maxItems; i++){
this.feeditems[i].setAttribute("ctitle", this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue)
this.feeditems[i].setAttribute("clink", this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue)
this.feeditems[i].setAttribute("cdescription", this.feeditems[i].getElementsByTagName("description")[0].firstChild.nodeValue)
}

I think he might have meant this to be in the php file.
He's been nice enough to write a little loop that will go thru 5 times.
The latter part of the code in the tutorial is about fetching the info from the stored file. If you use his to only "fetch" 5 I think that should do it.

ehartnett00
02-20-2007, 03:56 PM
I think he might have meant this to be in the php file.
He's been nice enough to write a little loop that will go thru 5 times.
The latter part of the code in the tutorial is about fetching the info from the stored file. If you use his to only "fetch" 5 I think that should do it.

I must be missing something. I've read through your post several times but am not comprehending. I'm not seeing enough difference between the original code:



for (var i=0; i<this.feeditems.length; i++){


and Shyam's code


var maxItems = this.feeditems.length <= 5 ? this.feeditems.length : 5;
for (var i=0; i<maxItems; i++){


to cause the ticker to no longer continuously cycle through all 5 posts.

Thanks.

FJbrian
02-20-2007, 06:46 PM
In the last sentence of your post you stated "I would prefer to limit it to only the last 4 or 5."
What do you mean by "it"

ehartnett00
02-21-2007, 02:52 PM
In the last sentence of your post you stated "I would prefer to limit it to only the last 4 or 5."
What do you mean by "it"

Sorry if I was unclear. Let's say I've written 10 posts in the last two months - instead of the ticker displaying all 10 and repeating, which it does now, I would rather the ticker only repeat the last 5, therefore showing only the most recent posts. Shyam's code worked great in that it limited the number of posts displayed to 5, which is what I'm after, but with his code the 5 posts are only displayed in the ticker once and then the ticker stops on the 5th post.

FJbrian
02-24-2007, 12:27 AM
just loop it back around and start the process again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum