【问题标题】:Fade in/out, cycling RSS news feed using PHP使用 PHP 淡入/淡出、循环 RSS 新闻提要
【发布时间】:2014-05-01 05:12:22
【问题描述】:

我有一些显示我的 RSS 项目的 PHP 代码,我限制为 1 个。我想让代码循环通过我的 RSS 项目,并具有淡入淡出效果。我可能可以计算出淡入淡出的 jQuery,但让它循环是我的主要问题。

<?php
$rss = new DOMDocument();
$rss->load('http://www.huffingtonpost.com/feeds/news.xml');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array(
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
    );
    array_push($feed, $item);
}
$limit = 1;
for ($x = 0; $x < $limit; $x++) {
    $title       = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link        = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $date        = date('l F d, Y', strtotime($feed[$x]['date']));
    echo '<br><p><strong><a href="' . $link . '" title="' . $title . '">' . $title . '</a></strong><br>' . $description . '</p>';
}
?>

【问题讨论】:

  • 您能否详细解释一下当前周期的问题是什么?
  • 目前它根本不骑自行车,我不知道为什么。
  • 为什么使用 $limit = 1;这将只允许显示一条记录。所以你无法确定当前的循环作品不是。

标签: php jquery rss cycle


【解决方案1】:

这是一个简单的问题,您的$limit 是静态的并设置为1。要查找数组值的数量,请使用 count()

$limit = count($feed);

【讨论】:

  • 虽然这不是我想要做的,但使用您的示例显示所有帖子,然后使用 jQuery 循环脚本淡入和淡出/显示:无,我能够实现我想要的.谢谢。
  • @Aquious 不客气,我没有提到 jQuery 代码的原因是因为这与 PHP 无关。效果只有在 PHP 完成后才会出现,我不确定您是否想要滚动效果。
猜你喜欢
  • 2015-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-19
  • 1970-01-01
  • 2014-12-21
  • 2013-07-14
  • 2014-06-12
相关资源
最近更新 更多