0

次のサンプル プラグインを使用すると、カスタム フィード URL にアクセスして、カスタマイズした RSS コンテンツを出力できます。この場合、URL は *http:///?feed=custom_user_feed* です。問題は、形式が正しくなく、Google Chrome がフィードとして認識しないことです。一方、IEとFirefoxはそうです。

/* Plugin Name: Sample Custom User Feed  */

add_action('init', array(new custom_user_feed, "add_feed"));

class custom_user_feed {

    protected $feed_query = 'custom_user_feed';
    protected $title = 'custom user feed sample';
    protected $link = 'http://www.stackoverflow.com';
    protected $urls = array(
        "http://stackoverflow.com/feeds"
        );
    protected $description = 'this is a sample to demonstrate a custom user feed.';
    protected $language = 'en-us';
    protected $itemlimit = 5;


    function add_feed() {
        add_feed($this->feed_query, array(&$this, "output_rss"));       
    }
    function output_rss() {
        $feed = fetch_feed($this->urls);
        $feed->set_item_limit($this->itemlimit);
        echo '<?xml version="1.0" encoding="UTF-8" ?>';
    ?>          
        <rss version="2.0">
        <channel>
            <title><?php echo $this->title; ?></title>
            <link><?php echo $this->link; ?></link>
            <description><?php echo $this->description; ?></description>
            <language><?php echo $this->language; ?></language>         

            <?php
            foreach($feed->get_items() as $item) {
            ?>              
                <item>
                    <title><?php echo $item->get_title(); ?></title>
                    <link><?php echo $item->get_permalink(); ?></link>
                    <description>
                        <?php echo $item->get_description(); ?>
                    </description>
                </item>

            <?php
            }
            ?>
        </channel>      
        </rss>
    <?php
    }
}

誰かがフォーマットのエラーを見つけることができますか? ありがとう。

4

1 に答える 1

1

あなたも使う必要があるかもしれませheader('Content-Type: text/xml');ん...

于 2012-10-13T08:31:14.820 に答える