获取帖子ID作为单独的RSS提要项目

时间:2013-10-10 作者:Chelseawillrecover

我正在寻找一种在RSS提要中显示或回显每个帖子ID的方法。基本上当我访问my RSS feed site, 我得到以下XML项:<title>, <link>, <comments>, <category>, <pubDate>, <guid isPermaLink>, <description>.

当我在代码中使用Google函数时

var url = \'http://howtodeployit.com/category/daily-devotion/feed/\';
        $.ajax({
        type: "GET",
        url: document.location.protocol + \'//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=\' + encodeURIComponent(url),
        dataType: \'json\',
返回的对象包括标题、链接、作者、publishedDate、contentSnippet。。。

我还想返回的是帖子ID,但不确定如何让我的WordPress将其包含在XML中。

1 个回复
SO网友:Chelseawillrecover

我是如何解决这个问题的?

步骤1:从我的WordPress Permalink设置中,我选择了自定义结构并添加了/%post\\u id%/这意味着我的结果将采用以下格式:

<myurl>/<postID>
步骤2:为了让我更容易编写regex查询,我使用了如下拆分命令:

var postlink = entry.link;
var id = postlink.split(/\\//)[3];
(///)[3] 只需将URL按斜杠数拆分,并只取第三位,即我的postID所在的位置。

我希望这对我这个职位的其他人有用。

结束

相关推荐

Pagination of RSS2 feed

如何对RSS2提要进行分页?我当前的RSS链接类似于:http://www.example.com/?feed=rss2 我试过:http://www.example.com/?feed=rss2&page=2 但是WordPress仍然返回相同的结果集,因为我在仪表板>设置>阅读>联合提要显示最新的(当然我有10多个帖子)