简体   繁体   中英

How to update a RSS feed presented in a slideshow?

I'm trying to put a rss feed on my webpage and would like to present the articles in a slideshow (Cycle 2).

I'm using a php script ("functions.php)to get the feed and everything works fine but I need help on how to update the feed every 5 minute to check if there are any new articles in the feed.

This is what I have in my 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; ?>

Update:

I've tried with this code. But it shows all articles at the same time - no cycling:

<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>

Any ideas?

为此,您需要Javascript / jQuery,请在此处查看: 带计时器的Jquery / Ajax调用,因此基本上您正在设置一个每5分钟调用一次的函数,该函数提取新数据并将其插入到幻灯片放映的区域中位于(jQuery .html()函数在这里会派上用场)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM