【问题标题】:My RSS feed only show few posts我的 RSS 提要只显示很少的帖子
【发布时间】:2017-03-24 12:33:32
【问题描述】:

我正在尝试使用 PDO 为我的 CMS 创建自动供稿。
这是我的代码。它有效,但只显示很少的帖子。我的代码有什么问题。

<?php
include('dbcon.php');
header("Content-Type: application/rss+xml; charset=ISO-8859-1");
//header("Content-Type: application/rss+xml; charset=utf-8"); 
echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"  xmlns:dc="http://purl.org/dc/elements/1.1/">';
echo '<channel>';
?>
    <title>Authorized Honda Auto Dealer | Serang Cilegon</title>
    <link>https://hondaautoserang.com/</link>
    <atom:link href="https://hondaautoserang.com/feed/" rel="self" type="application/rss+xml"/>
    <description>authorized honda auto dealer: dealer resmi mobil honda serang &amp; honda cilegon. beli mobil di serang terbukti lebih murah. Cek info harga &amp; promo terbaru: 087774040777.</description>
    <language>id-id</language>
    <copyright>Copyright (C) 2017 hondaautoserang.com</copyright>
    <?php
    $sqlFeed = "SELECT * FROM honda_post ORDER BY id DESC";
    $execFeed = $pdo->query($sqlFeed);
    $execFeed->execute();
    $fetchFeed = $execFeed->fetchAll(PDO::FETCH_ASSOC);
    if ($fetchFeed){
        foreach($fetchFeed as $r){
            $id = $r['id'];
            $title = $r['title'];
            $description = $r['description'];
            $publisher = $r['publisher'];
            $article = $r['article'];
            $image = $r['image'];
            $url = $r['url'];
            $date = $r['date'];
            $category = $r['category'];
            //tampilkan
            echo '<item>';
            echo '<title>'.$r['title'].'</title>';
            echo '<description>'.$r['description'].'</description>';
            echo '<category>'.$r['category'].'</category>';
            //echo '<content:encoded><![CDATA['.html_entity_decode($article, ENT_QUOTES, 'utf-8').']]></content:encoded>';
            echo '<link>'.$r['url'].'</link>';
            echo '<pubDate>'.$r['date'].'</pubDate>';
            //echo '<dc:creator>'.$r['publisher'].'</dc:creator>';
            echo '<guid isPermaLink="true">'.$r['url'].'</guid>';
            echo '</item>';
            }
        }
    ?>
<?php

echo '</channel>';
echo '</rss>';
?>

当我更改为 ORDER BY id ASC 时,只有 10 个帖子显示 (目前已发布 21 篇格式正确的帖子)。

【问题讨论】:

  • 证明。这是 rss 页面:hondaautoserang.com/feed
  • 这意味着您的代码在表中显示确切的记录数。
  • @YourCommonSense 等等,我在 google chrome 中看到我的提要显示所有帖子(如我所愿),但在 mozilla 中没有。是因为“标题”吗?
  • 老实说,我不知道。很可能只是 Mozilla

标签: php rss rss2


【解决方案1】:

当我重新检查我的 pdo 代码时,没问题。但这是因为根据 mozilla 浏览器google feedburner,该标题中的 & 号无效

解决方案: 所有&符号必须更改为&amp;amp; 然后我用它来改变&lt;title&gt;,&lt;description&gt;中的所有&amp;,方法如下:

$title = str_replace('&', '&amp;', $r['title']);
$description = str_replace('&', '&amp;', $r['description']);

它按我的意愿工作

以下是参考资料:Getting a The entity name must immediately follow the '&' in the entity reference error in java, but I dont have any ampersands in my xml file

注意:
但是,这个问题不是重复的,因为这个问题与参考文献不同:p

【讨论】:

    【解决方案2】:

    您是否尝试过以下方法? :

    $sqlFeed = "SELECT * FROM honda_post ORDER BY id DESC LIMIT 21";

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 2020-01-25
      • 2020-08-08
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多