Forum

Thread tagged as: Question, Blog, MailChimp

RSS not showing content, but it is in the code

A bit confused here. I've got the basics of my RSS feed setup - the rss.php file, the rss_post.html template. When I view the feed in Firefox, I see only the hard-coded title and subtitle. Not the posts. But when I view the code, I see everything I should....the post titles, descriptions, etc.

I moved on and tried connecting this RSS feed to MailChimp - but when I enter the URL that I am seeing the correct code (but not the regular view), MailChimp gives me an error: "Connecting to url failed"

Any ideas what I am missing? Here's my code:

rss.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="https://www.w3.org/2005/Atom">
    <channel>
        <title>Community RSS Feed</title>
        <link><?php echo PerchUtil::html($domain); ?>/dev-community/</link>
        <description>Description will be here</description>
        <atom:link href="<?php echo PerchUtil::html($domain); ?>/dev-community/rss.php" rel="self" type="application/rss+xml" />
        <?php
            perch_blog_custom(array(
                'template'=>'rss_post.html',
                'count'=>100,
                'sort'=>'postDateTime',
                'sort-order'=>'DESC'
                ));
        ?>
    </channel>
</rss>

rss_post.html

<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>
</item>
Leigh C

Leigh C 0 points

  • 3 years ago

Hi Leigh

I'm wondering if you've told your server to serve up php files as xml?

i.e. Added something like this in your htaccess file?

RewriteRule (.*).xml(.*) $1.php$2 [nocase]

The only other thing I can think of is if your xml is outputting the urls as http when you are on an https site?

Jon

Leigh C

Leigh C 0 points

Thanks for the ideas John. I tried the HTACCESS addition and it made no difference. :( I was hoping that would do the trick - arg. Yes, it's an HTTPS site, with a rewrite from HTTP, so how would I learn if it's outputting incorrectly? Especially when the code looks correct, but not the displaying. Odd.

Leigh C

Leigh C 0 points

I just used a feed validator - https://validator.w3.org/feed

And got these results:


This feed does not validate. line 16, column 3: Undefined description element: pubDate [help] <pubDate>Thu, 15 Mar 2018 07:30:00 +0000</pubDate> ^ line 17, column 2: XML parsing error: <unknown>:17:2: mismatched tag [help] </item><item> ^ In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation. line 7, column 108: Self reference doesnt match document location [help] ... rel="self" type="application/rss+xml" /> ^

So then I did this:

  1. Removed the "<![CDATA[ " and ending tag "]]>" surrounding the excerpt.
  2. Added striptags="true" to the excerpt line

Now it validates! It's showing the proper lines in Firefox, and MailChimp is now accepting the link.

So what happened here? Why did I need to fiddle with this myself to get it right? Why does the Perch documentation show that extra "CDATA" piece and not mention that stripping the HTML tags from the except? Did I just get lucky?

The other thing that I know borks rss feeds is if you've got extra whitespace. Take out any carriage returns that might be at the end of your template(s).

Leigh C

Leigh C 0 points

Thanks John - just edited my reply above - got it working, but I'm not totally sure why! No extra spaces - that was the first thing I checked :)

Does the page render if you reduce the xml content to just, say, the title?

Also - is the closing description tag in the wrong position?

Glad to hear it - playing forum tennis it seems!

Leigh C

Leigh C 0 points

Indeed! For others who hit this snag, here's my rss_post.html code with the updates I mentioned above:

<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><perch:blog id="excerpt" encode="false" striptags="true" /></description>
   <pubDate><perch:blog id="postDateTime" format="D, d M Y H:i:s O" /></pubDate>
</item>