Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RSS Ajax JavaScript ticker - Limiting the number of posts displayed?

    Hello.

    I'm using the RSS Ajax JavaScript ticker 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. 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.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    this should do the job i guess

    somewhere in rssticker.js do this

    Code:
    //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)
    }

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shyam View Post
    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?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Adirondacks
    Posts
    516
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by shyam View Post
    this should do the job i guess

    somewhere in rssticker.js do this

    Code:
    //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.
    Last edited by FJbrian; 02-20-2007 at 03:28 PM.

  • #5
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FJbrian View Post
    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:

    Code:
    for (var i=0; i<this.feeditems.length; i++){
    and Shyam's code
    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.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Adirondacks
    Posts
    516
    Thanks
    4
    Thanked 4 Times in 4 Posts
    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"

  • #7
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FJbrian View Post
    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.

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    Adirondacks
    Posts
    516
    Thanks
    4
    Thanked 4 Times in 4 Posts
    just loop it back around and start the process again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •