• Hi all!

    Does anybody know if it’s possible to parse php code inside posts in RSS 2.0 feed with RunPHP or somehow else?
    Thanks in advance.

Viewing 14 replies - 1 through 14 (of 14 total)
  • You’ll have to edit your feed generator files (wp-rss2.php/wp-atom.php) to do what you want. They have a loop just like the main of WP, so you can get a post’s content’s and process it to your heart’s content.

    Save it as a new file, and point your feed reader at it.

    Thread Starter Ally

    (@ally)

    I can’t get it working whatever i do :-((((
    So, http://mydomain.com/feed/rss2 is the rss feed. It contains something like that:
    ——————-
    – <content:encoded>
    – <![CDATA[
    test
    <?php echo “12345678910”; ?>

    ]]>
    </content:encoded>
    ——————-
    What should i do in order to have php tags parsed BEFORE they appear inside CDATA?
    May be someone could point me the right direction?
    Help me, please!

    Thread Starter Ally

    (@ally)

    Anyone?

    Ally, maybe you need to be more specific. the <?php ... ?> “tags” as you call them are parsed perfectly fine in the feed generator files.

    Maybe you’re trying to put them in places that are already enclosed in PHP tags? In this case, you can leave them off and type in the PHP code directly.

    Otherwise, what exactly do you want to achive?

    Thread Starter Ally

    (@ally)

    My RSS example:


    <?xml version="1.0" encoding="utf-8" ?>
    - <!-- generator="wordpress/1.2.2"
    -->
    - <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    - <channel>
    <title>My Site Title</title>
    <link>http://mydomain.com</link>
    <description>babblings!</description>
    <copyright>Copyright 2005</copyright>
    <pubDate>Thu, 20 Jan 2005 23:08:15 +0000</pubDate>
    <generator>http://wordpress.org/?v=1.2.2</generator>
    - <item>
    <title>aswdsdfsdfd</title>
    <link>http://mydomain.com/2005/01/09/aaaa.html</link>
    <comments />
    <pubDate>Sat, 08 Jan 2005 22:51:20 +0000</pubDate>
    <category>General</category>
    <guid>http://mydomain.com/2005/01/09/aaaa.html</guid>
    <description>wefrwt fdtghryt thyjtyjtyj</description>
    - <content:encoded>
    - <![CDATA[
    <p>qwrewerwer<br />
    <?php echo "12345678910"; ?>
    </p>

    ]]>
    </content:encoded>
    <wfw:commentRSS />
    </item>
    - <item>
    <title>wwwwwwwww</title>
    <link>http://mydomain.com/2005/01/06/wwwwwwwww.html</link&gt;
    <comments />
    <pubDate>Wed, 05 Jan 2005 21:50:14 +0000</pubDate>
    <category>General</category>
    <guid>http://mydomain.com/2005/01/06/wwwwwwwww.html</guid&gt;
    <description />
    - <content:encoded>
    - <![CDATA[
    <p><?php include('inc.php'); ?>
    </p>

    ]]>
    </content:encoded>
    <wfw:commentRSS />
    </item>
    </channel>
    </rss>

    My posts contain php code, it is parsed well with runPHP on the pages of my site. All is ok on the site itself but not in RSS feed. Posts contain exactly the content above. What is wrong?
    Thanks in advance.

    Are you using this RunPHP or another one? I think there are at least 2 plugins with the same name. Assuming you’re using James van Lommel’s (the above linked one), insert the following line in wp-rss2.php directly below the initial <?php line.

    runphp_wp_head();

    Then either hack up the code in wp-rss2.php to always use the content of the post instead of the excerpt or, just go to Options -> Reading and make sure you’re showing “full text” instead of “summary” for your syndication feeds. This latter option is what I have done and it seems to work.

    EDIT: oops forgot the link

    Thread Starter Ally

    (@ally)

    Thank you so much! This worked!!!

    May be it’s also possible to make runPHP work with post’s excerpt in RSS somehow?

    For the older version of RunPHP plugin file, near the end, you’ll find this:

    add_filter("the_content", "run_php");

    Add lines for the ones you want to hit:

    add_filter("the_content", "run_php");
    add_filter("the_content_rss", "run_php");
    add_filter("the_excerpt", "run_php");
    add_filter("the_excerpt_rss", "run_php");

    Changes to the new version would be along the same lines.

    Kafkaesqui’s solution certainly works, but with one caveat.

    The problem with excerpts is that if your post does not have an explicit excerpt set, WordPress will generate one by just grabbing the first so many words. So excerpts may cut your php code in half. If that happens, you’re back to your original problem.

    Example. Suppose WordPress generates excerpts which are 12 words long for posts without explicit excerpts. The actual number is much larger, but let’s say it’s 12 for the sake of argument.

    Original post: Hello, this will echo some text, what will it be? <?php echo 'some text' ?>.
    Which would output as “Hello, this will echo some text, what will it be? some text.” if you’re using the full text in your RSS.

    Generated Excerpt: Hello, this will echo some text, what will it be? <?php echo
    Which would output as “Hello, this will echo some text, what will it be? <?php echo” if you’re using excerpts in your RSS.

    Oh, and for the 1.2b3 version, the lines you’re looking for are around line 75:

    Below
    add_filter('the_content', 'runphp_the_content', 1);

    add (for example)
    add_filter('the_excerpt_rss', 'runphp_the_content', 1);

    Thread Starter Ally

    (@ally)

    This didn’t worked. 🙁

    I finally maked it by setting the following:

    1) add_filter(‘the_excerpt’, ‘runphp_the_content’, 1);
    inside runPHP.php

    2) <description><![CDATA[<?php the_excerpt() ?>]]></description>
    instead of
    <description>the_excerpt_rss(get_settings(‘rss_excerpt_length’), 2)</description>
    inside wp-rss2.php

    Is it right? Is it possible to enclose description’s content in CDATA?

    I don’t know. Does it work? :)

    Thread Starter Ally

    (@ally)

    Yes. But i don’t know if it’s correct to use CDATA and html tags inside the description.

    Ah, I see, sorry. :)

    Yes, I believe you can. To be more specific: I’ve seen other people do this who are far more knowledgeable than I am. I myself don’t know.

    Thread Starter Ally

    (@ally)

    Thanks a lot for your help!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘RunPHP in RSS feed?’ is closed to new replies.