2017-01-21 25 views
1

所以,我基本上試圖顯示基於當前URL的特定RSS源。我在下面的解決方案中已經有所瞭解,但我不想在變量中指定URL,而是檢查當前的URL,然後執行/拉取我的rss提要。
下面的解決方案無法工作,因爲我需要對多個URL進行多重檢查。如果基於當前URL的語句(沒有指定)

jQuery(function($) { // display rss feed based on current URL 

// start conditions to display 3 feeds on different URLs 

    var url = 'http://localhost:8888/'; 

    if (url.indexOf('8888') > -1) { 
     $(".feed1").rss("http://www.thehollywoodgossip.com/rss.xml", 
     { 
     limit: 17, 
     entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>' 
     }) 
     $(".feed2").rss("http://www.thehollywoodgossip.com/rss.xml", 
     { 
     limit: 17, 
     entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>' 
     }) 
     $(".feed3").rss("http://www.thehollywoodgossip.com/rss.xml", 
     { 
     limit: 17, 
     entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>' 
     }) 
    } 
    if (url.indexOf('movies') > -1) { 
     $(".feed1").rss("http://www.thehollywoodgossip.com/rss.xml", 
     { 
     limit: 17, 
     entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>' 
     }) 
     $(".feed2").rss("http://www.thehollywoodgossip.com/rss.xml", 
     { 
     limit: 17, 
     entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>' 
     }) 
     $(".feed3").rss("http://www.thehollywoodgossip.com/rss.xml", 
     { 
     limit: 17, 
     entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>' 
     }) 
    } 

....... 

請注意,供稿網址將有所不同。這只是一個例子。

+0

是關於如何以查詢網址這個問題? – Reyraa

回答

1

而不是

var url = 'http://localhost:8888/'; 

var url = window.location.href;