Results 1 to 3 of 3

Thread: gAjax RSS Feeds Displayer v2.0 with read more link

  1. #1
    Join Date
    Jul 2016
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default gAjax RSS Feeds Displayer v2.0 with read more link

    1) Script Title: gAjax RSS Feeds Displayer v2.0

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...sdisplayer.htm

    3) Describe problem: i want to add a "read more" link at the end of the description.
    With additional code i already made it work that it shows a certain amount of words from the description, so it makes sense to put a read more link there


    I tried putting the "read more link" in the function gfeedfetcher(divid, divClass, linktarget). However I don't know how to put the url there as i get confused with all the " ' etc.
    Or maybe there is a better solution? I am not so familiar using javascript.


    thank you



    Code:
    function gfeedfetcher(divid, divClass, linktarget){
    	this.linktarget=linktarget || "" //link target of RSS entries
    	this.feedlabels=[] //array holding lables for each RSS feed
    	this.feedurls=[]
    	this.feeds=[] //array holding combined RSS feeds' entries from Feed API (result.feed.entries)
    	this.feedsfetched=0 //number of feeds fetched
    	this.feedlimit=5
    	this.showoptions="" //Optional components of RSS entry to show (none by default)
    	this.outputtemplate="<hr>{title} {label}<br />{date}<br />{description}<br /><br /><a href=' + feeds[i].link + '>Read more...</a>" // output template for each RSS entry
    	this.regexprules=[] // array to hold regexp rules [regex, replacestr, field_to_apply_to]
    	this.sortstring="date" //sort by "date" by default
    	document.write('<div id="'+divid+'" class="'+divClass+'"></div>') //output div to contain RSS entries
    	this.feedcontainer=document.getElementById(divid)
    	this.containertag=["li", "<li>"] // [tag to wrap around each rss entry, final tag]
    	this.onfeedload=function(){}
    }
    Thank you

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, first of all, you didn't have to edit the script at all. The change you made/were trying to make, can be made using the feed instance definetemplate function. However, if you want all feeds to have this new template, you can change it in the script as you have already done, just do it correctly (as I'm about to explain).

    The real mistake you made was to use feeds[i].link - which in the template has no meaning. What you want is the already available token {url}

    So, for example, using the first example feed on the demo page we could do (using it's init, without editing the script at all, impotant additions highlighted):

    Code:
    <script type="text/javascript">
    
    var cssfeed=new gfeedfetcher("example1", "example1class", "")
    cssfeed.addFeed("CSS Drive", "http://www.cssdrive.com/index.php/news/rss_2.0/") //Specify "label" plus URL to RSS feed
    cssfeed.displayoptions("date snippet") //show the specified additional fields
    cssfeed.setentrycontainer("li") //Display each entry as a list (li element)
    cssfeed.filterfeed(10, "title") //Show 10 entries, sort by date
    cssfeed.definetemplate("<hr>{title} {label}<br />{date}<br />{description}<br /><br /><a href=\"{url}\">Read more...</a>") // output template for this RSS entry
    cssfeed.init() //Always call this last
    
    </script>
    NOTES: By using the snippet as part of the displayoptions instead of description, we get a shorter version of the description. By defining the definetemplate here, we don't have to change the main script's outputtemplate string. Notice also the escaped (\") internal quotes for the template. It is always necessary in a code string to escape the like quotes which delimit the string. In this case it would be easier to do it this way:

    Code:
    cssfeed.definetemplate('<hr>{title} {label}<br />{date}<br />{description}<br /><br /><a href="{url}">Read more...</a>') // output template for this RSS entry
    (using single quotes to delimit the string, allowing for unescaped double quotes inside the string), but either way works.

    Here's another, perhaps better example (the snippets here are actually shorter, the css drive descriptions were short already):

    Code:
    <script type="text/javascript">
    
    var socialfeed=new gfeedfetcher("example2", "example2class", "_new")
    socialfeed.addFeed("Slashdot", "http://rss.slashdot.org/Slashdot/slashdot") //Specify "label" plus URL to RSS feed
    socialfeed.addFeed("Digg", "http://digg.com/rss/index.xml") //Specify "label" plus URL to RSS feed
    socialfeed.displayoptions("label datetime snippet") //show the specified additional fields
    socialfeed.setentrycontainer("div") //Display each entry as a DIV
    socialfeed.filterfeed(6, "label") //Show 6 entries, sort by label
    socialfeed.definetemplate('<hr>{title} {label}<br />{date}<br />{description}<br /><br /><a href="{url}">Read more...</a>') // output template for each RSS entry
    socialfeed.init() //Always call this last
    
    </script>
    Last edited by jscheuer1; 07-25-2016 at 02:52 PM. Reason: add last example
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2016
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Great! thank you.

    Yes I knew + feeds[i].link + didn't make any sense, but i didn't know {url} so i tired something.

    Anyway thanks again!

    I have another questions about image resizing but I will continue that in another topic

Similar Threads

  1. gAjax RSS Feeds Displayer - Edit Feeds Shown
    By dsol828 in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 08-01-2012, 07:11 PM
  2. gAjax RSS Feeds Displayer - ignore broken feeds?
    By kblm in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 05-24-2012, 10:18 PM
  3. Replies: 0
    Last Post: 09-05-2011, 09:18 AM
  4. gAjax RSS Feeds Displayer - can't display multiple feeds
    By nsbrown in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 06-06-2008, 08:40 AM
  5. gAjax RSS Feeds Displayer: Feeds with no publishedDate
    By mfreeman in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-30-2008, 07:56 AM

Bookmarks

Posting Permissions

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