0

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?

1 Answers1

1

You need Javascript/jQuery for this, have a look at this here: Jquery/Ajax call with timer so basically you are setting up a function that gets called every 5min and this function pulls the new data and inserts it in the area where the slideshow is located (the jQuery .html() function will come in handy here)

Community
  • 1
  • 1
Stefan
  • 2,164
  • 1
  • 23
  • 40