【问题标题】:How to update a RSS feed presented in a slideshow?如何更新幻灯片中呈现的 RSS 提要?
【发布时间】:2013-01-15 17:39:58
【问题描述】:

我正在尝试在我的网页上添加 rss 提要,并希望以幻灯片形式展示文章(第 2 周期)。

我正在使用 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>

有什么想法吗?

【问题讨论】:

    标签: php javascript jquery jquery-cycle


    【解决方案1】:

    为此您需要 Javascript/jQuery,请看这里:Jquery/Ajax call with timer 所以基本上您正在设置一个每 5 分钟调用一次的函数,该函数会提取新数据并将其插入幻灯片的区域位于(这里 jQuery .html() 函数会派上用场)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      相关资源
      最近更新 更多