我正在尝试使用PDO为我的CMS创建自动Feed
这是我的代码。它有效,但只显示了几个帖子。我的代码出了什么问题。
<?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个正确格式的帖子。)
答案 0 :(得分:1)
当我检查回我的pdo代码时,没问题。但这是因为根据 mozilla浏览器和 google feedburner ,该标题中的&符号无效。
解决方案:
所有&符号必须更改为&
然后,我使用此更改&
,<title>
中的所有<description>
,方法如下:
$title = str_replace('&', '&', $r['title']);
$description = str_replace('&', '&', $r['description']);
它按照我的意愿工作
注意:强>
但是,这个问题并不重复,因为问题与参考不同:p
答案 1 :(得分:-2)
您是否尝试过以下操作? :
$sqlFeed = "SELECT * FROM honda_post ORDER BY id DESC LIMIT 21";