Folks, I hope your collective wisdom can help me. The WP forums weren't exactly brimming with support.

Here's the sitation. I have my home page at example.com/index.php

My WordPress blog is at example.com/blog

My WordPress RSS feed is at example.com/blog/feed

On /index.php, I want to show the last four entries from my WP blog. To do this I have tried using Magpie (I also tried Simplepie which just gave be blank pages), like so;

nclude_once($inc['magpierss']);
$url = 'blog/feed';
$rss = fetch_rss($url);

I have used variations of $url each resulting in an error message, as follows;

blog/feed results in

Warning: MagpieRSS: Failed to fetch blog/feed (HTTP Error: Invalid protocol "") in /var/www/vhosts/example.com/httpdocs/inc/magpierss/rss_fetch.inc on line 238

http://example.com/blog/feed results in

Warning: MagpieRSS: Failed to fetch http://example.com/blog/feed (HTTP Response: HTTP/1.1 404 Not Found ) in /var/www/vhosts/example.com/httpdocs/inc/magpierss/rss_fetch.inc on line 238

blog/wp-rss2.php results in

Warning: MagpieRSS: Failed to fetch blog/wp-rss2.php (HTTP Error: Invalid protocol "") in /var/www/vhosts/example.com/httpdocs/inc/magpierss/rss_fetch.inc on line 238

http://example.com/blog/wp-rss2.php and

Warning: MagpieRSS: Failed to fetch http://example.com/blog/wp-rss2.php (HTTP Response: HTTP/1.1 404 Not Found ) in /var/www/vhosts/example.com/httpdocs/inc/magpierss/rss_fetch.inc on line 238

$_SERVER['DOCUMENT_ROOT'].'/blog/wp-rss2.php' results in

Warning: MagpieRSS: Failed to fetch /var/www/vhosts/example.com/httpdocs/blog/wp-rss2.php (HTTP Error: Invalid protocol "") in /var/www/vhosts/example.com/httpdocs/inc/magpierss/rss_fetch.inc on line 238

It's boiled down to apparently being because Magpie uses Snoopy which uses fsockopen(). Obviously, being a WP feed it needs to be parsed by PHP so I'm presuming 'opening' it with fsockopen doesn't do that, just like fopen() wouldn't.
Oh and accessing both http://example.com/blog/feed and http://example.com/blog/wp-rss2.php both show the full, well-formed RSS feed as it should be.

So.... does ANYONE know of a way around this, or another feed parser I could use.

FYI allow_urls_fopen is disabled in my php.ini to prevent script injection vulnerabilities.

Before I finish I did try this; I created a file (/feed.php) which used a PHP include to include the RSS feed (with the intention of giving Magpie $url = '/feed.php'). Now, strangely it did include the feed but not all of it. The <items> tags and everything in between (the items!) were missing (yet the Channel and RSS tags were in place)! I used the exact same PHP-include in /index.php and it pulled in the entire feed, complete with Items. This one is particular bizarre - ideas on a post card.

Thanks very much in advance for your help... I'm really struggling with this one!

    I do not know anything about Magpie, but typically you should be able to access your Wordpress RSS feed via "http://example.com/blog/feed/". Have you confirmed that that works if directly entered in your browser's address bar?

      Yep - the feeds definitely work when entered into the browser. I lost count of how many times I double checked that 🙂

        What is your host's allow_url_fopen setting? You can check it via a phpinfo(), or just run the following:

        <?php
        $value = ini_get('allow_url_fopen');
        var_dump($value);
        

          allow_url_fopen is off. I've been told this will not be the issue because Snoppy uses fsockopen.

          Is that right?

            ppeter;10881526 wrote:

            allow_url_fopen is off. I've been told this will not be the issue because Snoppy uses fsockopen.

            Is that right?

            Sounds right, but I'm not any sort of sockets guru, so I don't know what other "gotchas" may be there.

            Personally, I'd probably grab the feed via a [man]cURL[/man] call, then either parse it myself via [man]SimpleXML[/man] or use something like the PEAR XML_Feed_Parser.

              Thanks NogDog, I'll give those suggestions a try. I wish the WP forums were this helpful!

                7 days later

                I've finally found a solution so here it is for those who have similar issues.

                (NogDog: I didn't end up trying those suggestions, but thanks again.)

                1. I created a new file within the WordPress directory (call it what you like) with a WP 'loop' which prints out the last 3 posts, like so:
                <?php
                if (empty($wp)) {
                	require_once('wp-load.php');
                }
                ?>
                <?php query_posts('showposts=3'); ?>
                <?php if (have_posts()) : ?>
                
                <?php while (have_posts()) : the_post(); ?>
                
                    <div id="post-<?php the_ID(); ?>" class="post">
                        <h4><a href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
                        <p><span class="date"><?php the_time('jS F, Y'); ?></span> - <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>">continue reading...</a></p>
                    </div>
                
                <?php endwhile; ?>
                
                <?php else : ?>
                
                    <h4 class="center">Not Found</h4>
                    <p class="center">Sorry, but you are looking for something that isn't here.</p>
                    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
                
                <?php endif; ?>
                
                1. I used a normal PHP-include in /index.php to include the new file.

                2. That's it!

                Phil

                  Write a Reply...