【发布时间】: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 & honda cilegon. beli mobil di serang terbukti lebih murah. Cek info harga & 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