2013-01-11 28 views
0

我正在嘗試在我的網頁上放置一個RSS feed,並且想要以幻燈片形式呈現這些文章(週期2)。如何更新幻燈片中呈現的RSS提要?

我正在使用php腳本(「functions.php)來獲取提要並且一切正常,但我需要幫助如何每5分鐘更新一次提要以檢查提要中是否有新文章。

這是我在我的div:

<div id="rss-news" class="cycle-slideshow" 
data-cycle-fx="fade" 
data-cycle-speed="500" 
data-cycle-timeout="6000" 
data-cycle-slides="> div" 
> 
<?php 
include("functions.php"); 
//Runs function with feed url and number of posts as arguments 
$my_rss = fetch_rss_feed('http://www.thefeed.com/rss', 10); 
?> 

<?php foreach ($my_rss as $k => $v) : ?> 
<div> 
<span class="title"><b><?php echo $v['title']; ?></b></span> 
<!--<span class="date"><?php echo $v['date']; ?></span> --> 
<span class="descr"><?php echo $v['descr']; ?></span> 
<span class="enclosure"><img src="<?php echo $v['enclosure']; ?>"></span> 
</div> 
<?php endforeach; ?> 

更新:

我試過這個代碼,但它顯示在同一時間的所有文章 - 沒有循環:

<html> 
<head> 
<title>Test</title> 
<!--<link rel="stylesheet" href="style.css">--> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<script src="http://malsup.github.com/jquery.cycle2.js"></script> 
<script type="text/javascript"> 
function update() { 
$("#notice_div").html('Loading..'); 
$.ajax({ 
type: 'GET', 
url: 'getrss.php', 
timeout: 2000, 
success: function(data) { 
    $("#div-one").html(data); 
    $("#notice_div").html(''); 
    window.setTimeout(update, 10000); 
}, 
error: function (XMLHttpRequest, textStatus, errorThrown) { 
    $("#notice_div").html('Timeout contacting server..'); 
    window.setTimeout(update, 60000); 
} 
}); 
} 
$(document).ready(function() { 
update(); 
}); 
</script> 
</head> 
<body> 
<div id="div-one" class="cycle-slideshow" 
data-cycle-fx="fade" 
data-cycle-speed="500" 
data-cycle-timeout="6000" 
data-cycle-slides="> div" 
></div> 
<div id="notice-div"></div> 
</body> 
</html> 

有什麼想法?

回答

1

您需要使用Javascript/jQuery才能正常瀏覽此頁面:Jquery/Ajax call with timer基本上,您設置了一個函數,每5分鐘調用一次該函數,並將該數據插入幻燈片顯示的區域位於(這裏的jQuery .html()函數會派上用場)