Hi there, I just wondering if can I reuse content (e.g. news articles) from a mainsite.com to site_A.com, site_B.com and site_C.com, of course, all of them using Perch; my idea is to publish news on mainsite.com and automatically publish on the other sites; is it possible to do this? I've tried to to do this using an RSS feed but I can't set up an image for each article and even worst, I can't set up a css style for the xml. Thanks
reuse content on different domains
- Alejandro
- Thread is marked as Resolved.
-
-
drewm
Approved the thread. -
There's a few different approaches you could take. Are the sites all on the same hosting? Can they all connect to one database?
-
Hi Drewm, no really, they are on the same reseller account but separate account each. No, they are on different database.
Thanks.
-
In which case an RSS or JSON feed would be a good option between the sites.
-
Thanks Drew
Any suggestions on how to implement this using JSON? I did not find information in Perch Docs and Forum.
-
Are you using Perch or Runway?
-
Hi Drew,I'm using Perch, at the moment, but I can move to Runway if necessary, no problem.
-
There's probably three parts to this:
1. Produce the JSON feeds on your primary site
2. Write code (probably an app) to parse and use the JSON on the secondary sites
3. Figure out how/when those feeds should be refreshed (possibly a scheduled task)
For an experienced PHP developer this should be very straightforward, so it'll depend on your level of experience.
-
Hi Drew.
Thank you for your answer. I'm not an experienced PHP developer, so, I've been traying to do this using a XML feed.
My code for rss_post.html
Code- <item>
- <title><perch:blog id="postTitle" /></title>
- <link><perch:blog id="domain" /><perch:blog id="postURL" /></link>
- <guid><perch:blog id="domain" /><perch:blog id="postURL" /></guid>
- <description><![CDATA[<perch:blog id="excerpt" encode="false" />]]></description>
- <pubDate><perch:blog id="postDateTime" format="D, d M Y H:i:s O" /></pubDate>
- <enclosure url="https://mysite.com<perch:blog id="image" type="image" crop />" length="123456789" type="image/jpeg" />
- </item>
My feed rss.php on my news folder
PHP- <?php include('../perch/runtime.php');?>
- <?php
- $domain = 'https://'.$_SERVER['HTTP_HOST'];
- PerchSystem::set_var('domain', $domain);
- header('Content-Type: application/rss+xml');
- echo '<'.'?xml version="1.0"?'.'>';
- ?>
- <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
- <channel>
- <title>News</title>
- <link><?php echo PerchUtil::html($domain); ?>/news/</link>
- <description>News</description>
- <atom:link href="<?php echo PerchUtil::html($domain); ?>/news/rss.php" rel="self" type="application/rss+xml" />
- <?php
- perch_blog_custom(array(
- 'template'=>'blog/rss_post.html',
- 'count'=>6,
- 'sort'=>'postDateTime',
- 'sort-order'=>'DESC',
- ));
- ?>
- </channel>
- </rss>
my page to show rss feed
PHP- <?php
- $xml_feed = new DOMDocument();
- $xml_feed->load('https://mysite.com/news/rss.php');
- $feed_items = array();
- foreach ($xml_feed->getElementsByTagName('item') as $node) {
- $item = array (
- 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
- 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
- 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
- 'enclosure' => $node->getElementsByTagName('enclosure')->item(0)->nodeValue,
- 'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
- );
- array_push($feed_items, $item);
- }
- foreach ($feed_items as $feed_item) { ?>
- <table style="margin-left: 20px;" border="0" cellpadding="0" cellspacing="0" width="360">
- <tbody>
- <tr>
- <td height="140" width="230">
- <span><?php echo $feed_item["pubDate"] ?></span>
- <h2><?php echo $feed_item["title"] ?></h2>
- <a class="ver_mas" href="<?php echo $feed_item["link"] ?>">ver más</a>
- </td>
- <td align="right" width="130">
- <div><?php echo $feed_item["enclosure"] ?></div>
- </td>
- </tr>
- </tbody>
- </table>
- <?php } ?>
My problem is that I can't see post image on <item>. I've used
on <enclosure> because I don't know how can I obtain this value.
Thanks for your help.
-
I’m not quite sure what you’re asking. Is the image path not being output into the template? If not, what do you get, and what does that field look like in your post.html template? Do the attributes match?
-
Hi Drew, Thank you for your answer. My issue is: I can't see the blog image ("image") on my page to show rss feed. Path to the image is ok.
post.html
Code- <header class="cs-post-single-title">
- <div class="cs-post-category-solid cs-clearfix">
- <perch:categories id="categories" set="blog" label="Categoria" display-as="checkboxes" >
- <a href="archive.php?cat=<perch:category id="catSlug" type="slug" />" class="p-category"><perch:category id="catTitle" type="text" /></a>
- </perch:categories>
- </div>
- <h3><perch:blog id="postTitle" type="text" title="true" required="true" label="Titulo" size="xl" order="1"/></h3>
- <div class="cs-post-meta cs-clearfix">
- <span><i class="fa fa-calendar" aria-hidden="true"></i>
- <perch:blog id="postDateTime" type="date" time="true" format="%A, %e %B %Y" fieldorder="dmy" divider-before="Fecha de publicacion" order="64" /></span>
- </div>
- </header>
- <article class="cs-single-post">
- <div class="cs-single-post-content">
- <perch:if exists="image">
- <div class="cs-single-post-media">
- <div class="cs-media-credits"><perch:blog id="caption" type="text" textile="true" label="lectura foto" size="xl" order="41"/>
- </div>
- <img src="<perch:blog id="image" type="image" width="610" height="407" crop="true" label="Foto" order="40" />" alt="" />
- </div>
- </perch:if>
- <div class="cs-single-post-paragraph">
- <perch:blog id="postDescHTML" type="textarea" editor="ckeditor" html="true" label="Contenido2" required="true" size="xl" order="3"/>
- </div>
- </div>
- </article>
- <perch:blog id="image" type="image" width="60" height="60" crop="true" suppress="true" />
- <perch:blog id="image" type="image" width="100" height="75" crop="true" suppress="true" />
- <perch:blog id="image" type="image" width="120" height="80" crop="true" suppress="true" />
-
I can't see the blog image ("image") on my page to show rss feed. Path to the image is ok.
Sorry, I don't understand what you mean by this.
-
Maybe, if you can take a look at my test page https://patagonia.uach.cl/index_rss_externo.php section "Noticias" (scroll down in the middle), I hope to see an image but it does not appear, <div></div> is empty.
Thanks
-
Where is the code for this page? This is different than the templates you've shown us.
-
Yes, I'm trying other way, here you go
PHP- <div class="container">
- <?php
- $xml_feed = new DOMDocument();
- $xml_feed->load('https://patagonia.uach.cl/noticias/rss.php');
- $feed_items = array();
- foreach ($xml_feed->getElementsByTagName('item') as $node) {
- $item = array (
- 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
- 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
- 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
- 'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
- 'image' => $node->getElementsByTagName('image')->item(0)->nodeValue,
- );
- array_push($feed_items, $item);
- }
- foreach ($feed_items as $feed_item) { ?>
- <table style="margin-left: 20px;" border="0" cellpadding="0" cellspacing="0" width="360">
- <tbody>
- <tr>
- <td height="140" width="230">
- <span><?php echo $feed_item["pubDate"] ?></span>
- <h2><?php echo $feed_item["title"] ?></h2>
- <a class="ver_mas" href="<?php echo $feed_item["link"] ?>">ver más</a>
- </td>
- <td align="right" width="130">
- <div><?php echo $feed_item["image"] ?></div>
- </td>
- </tr>
- </tbody>
- </table>
- <?php } ?>
- </div>
-
$node->getElementsByTagName('image')
Your tag is called img not image.
-
Ok, I did a change but still not working
PHP- <?php
- $xml_feed = new DOMDocument();
- $xml_feed->load('https://patagonia.uach.cl/noticias/rss.php');
- $feed_items = array();
- foreach ($xml_feed->getElementsByTagName('item') as $node) {
- $item = array (
- 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
- 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
- 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
- 'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
- 'img' => $node->getElementsByTagName('img')->item(0)->nodeValue,
- );
- array_push($feed_items, $item);
- }
- foreach ($feed_items as $feed_item) { ?>
- <table style="margin-left: 20px;" border="0" cellpadding="0" cellspacing="0" width="360">
- <tbody>
- <tr>
- <td height="140" width="230">
- <span><?php echo $feed_item["pubDate"] ?></span>
- <h2><?php echo $feed_item["title"] ?></h2>
- <a class="ver_mas" href="<?php echo $feed_item["link"] ?>">ver más</a>
- </td>
- <td align="right" width="130">
- <div><?php echo $feed_item["img"] ?></div>
- </td>
- </tr>
- </tbody>
- </table>
- <?php } ?>
-
Here's my updated rss_post.html template:
Code- <item>
- <title><perch:blog id="postTitle" /></title>
- <link><perch:blog id="postURL" /></link>
- <guid><perch:blog id="domain" /><perch:blog id="postURL" /></guid>
- <description><![CDATA[<perch:blog id="excerpt" encode="false" />]]></description>
- <pubDate><perch:blog id="postDateTime" format="D, d M Y H:i:s O" /></pubDate>
- <img src="https://patagonia.uach.cl<perch:blog id="image" type="image" width="100" height="75" crop="true"/>" />
- </item>
-
'img' => $node->getElementsByTagName('img')->item(0)->nodeValue,
Your tag has no nodeValue as it's an empty tag. You'll want to get the value of the src attribute here instead.
-
Thanks Drew