简体   繁体   English

如何显示要求在核心PHP上显示来自第三方站点的RSS feed?

[英]How can I display a requirement to show an RSS feed from a third party site on core PHP?

How to display daily news update in core PHP web site auto posting ? 如何在核心PHP网站自动发布中显示每日新闻更新? Core php web site Showing RSS Feed On Page 核心php网站在页面上显示RSS Feed

I have a requirement to show an RSS feed from a third party site. 我需要显示第三方站点的RSS提要。 I don't want to do this through the browser's RSS mechanism. 我不想通过浏览器的RSS机制执行此操作。 Instead I want to embed the feed (with styling) into a particular page. 相反,我想将提要(带有样式)嵌入到特定页面中。

My question is, can this be done just using the CMS admin? 我的问题是,可以仅使用CMS管理员来完成此操作吗? Is there a particular content type/part I can use? 我可以使用特定的内容类型/部分吗? Or would this have to be done programatically? 还是必须以编程方式完成?

I realise there are modules that I could download, but I see no support for RSS feeds for , which I'm using. 我意识到有一些模块可以下载,但是我看不到我正在使用的RSS feed的支持。 The ones I've tried are for later versions. 我尝试过的用于更高版本。

http://www.cnplus.co.uk/XmlServers/navsectionRSS.aspx?navsectioncode=12911 http://www.cnplus.co.uk/XmlServers/navsectionRSS.aspx?navsectioncode=12911

http://www.anglianwater.co.uk/_assets/media/xml/rss-news.xml http://www.anglianwater.co.uk/_assets/media/xml/rss-news.xml

If you are using WOrdpress CMS tool then it would be easy to integrate the RSS feed onto your page. 如果您使用的是WOrdpress CMS工具,则很容易将RSS feed集成到您的页面上。

Checkout https://wordpress.org/plugins/tags/rss-feed for plugins. 检出https://wordpress.org/plugins/tags/rss-feed中的插件。 I personally recommend https://wordpress.org/plugins/wp-rss-aggregator/ plugin as this is one of the best RSS plugin i have come accross. 我个人推荐https://wordpress.org/plugins/wp-rss-aggregator/插件,因为这是我遇到过的最好的RSS插件之一。

There are 2 ways to do this: 有两种方法可以做到这一点:

  1. Only load the content of the 3rd party feed inside the HTML documents using Javascript. 仅使用Javascript将第3方供稿的内容加载到HTML文档中。 This means that you will not "store" or "cache" the content from your servers... but that you will load content from a 3rd party site/application. 这意味着您不会“存储”或“缓存”服务器中的内容...,而是将从第三方站点/应用程序中加载内容。
  2. Store the content of the RSS feed in your backend and load it like the rest of your HTML documents using PHP. 将RSS feed的内容存储在您的后端,并使用PHP像其他HTML文档一样加载它。 To the frontend, the content from the RSS feeds will then be exactly like the rest of your content. 到前端,RSS提要中的内容将与其余内容完全一样。

This blog posts shows how to use the Superfeedr API with either approach. 这篇博客文章展示了如何通过两种方法使用Superfeedr API

$mypix = simplexml_load_file(' http://www.anglianwater.co.uk/_assets/media/xml/rss-news.xml '); $ mypix = simplexml_load_file(' http://www.anglianwater.co.uk/_assets/media/xml/rss-news.xml ');

$i=0; $ i = 0; foreach ($mypix->channel->item as $pixinfo) foreach($ mypix-> channel-> item为$ pixinfo)

{
    $title=$pixinfo->title;
    $link=$pixinfo->link;
    $description=$pixinfo->description;
    $pubdate=$pixinfo->pubDate;
  // $image=str_replace("_b.jpg","_s.jpg",$pixinfo->link[1]['href']);
    $title=strip_tags($title, '<br>');
   $link=htmlspecialchars($link);
     $description=strip_tags($description, '<br>');
     $pubdate=strip_tags($pubdate, '<br>');

    echo '<div class="row">
            <div class="box-sizing" style="border:1px; border-color:blue;">
                <p class="large text-muted">'.$title.'</p>
                <p class="large text-muted">'.$description.'</p>
                <p class="large text-muted">'.$pubdate.'</p>
            </div>
        </div>';

     if (++$i == 3) break;      

} 

Put above code in "php code" 将上面的代码放在“ php代码”中

if you get 如果你得到

rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0" rss xmlns:a10 =“ http://www.w3.org/2005/Atom”版本=“ 2.0”

type xml 输入xml

chnge $pubdate=$pixinfo->pubDate chnge $ pubdate = $ pixinfo-> pubDate

insted of 装的

$pubdate=$pixinfo->children(' http://www.w3.org/2005/Atom ')->updated; $ pubdate = $ pixinfo-> children(' http://www.w3.org/2005/Atom ')->已更新;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM