我的自定义 Wordpress RSS 在 http://feedvalidator.org/ 上返回错误 404



我在这里写信是因为我在为wordpress创建的自定义提要时遇到问题。

发生的事情是它似乎无效,我从 http://feedvalidator.org/
的回答是服务器返回了 HTTP 错误 404:未找到

以下是我如何调用我的自定义 rss 提要:

remove_all_actions( 'do_feed_rdf', 'do_feed_rdf', 10, 1 );
remove_all_actions( 'do_feed_rss', 'do_feed_rss', 10, 1 );
remove_all_actions( 'do_feed_rss2', 'do_feed_rss2', 10, 1 );
remove_all_actions( 'do_feed_atom', 'do_feed_atom', 10, 1 );
add_action( 'do_feed_rss2', 'rss2', 10, 1 );
function rss2( $for_comments ) {
    load_template( TEMPLATEPATH . '/feeds/feed.php' );
}
global $allfeeds;
$allfeeds = array(
      "news",
      "tour-dates",
      "bands",
      "videos",
      "tracks",
      "pictures",
      "festivals"
);
foreach ($allfeeds as $f){
    $f2 = preg_replace("/-/", "_", $f);
    eval("
                            function create_".$f2."_feed () {
                                load_template( TEMPLATEPATH . '/feeds/feed-".$f.".php');
                            }
                    ");
}
// Replace default feed rewrite rules
function customise_feed_rules($rules) {
    global $allfeeds;
    foreach ($allfeeds as $f){
        $new_rules["feed/".$f] = "index.php?feed=".$f."_feed";
    }
    return $new_rules + $rules;
}
// Add the custom feed and update rewrite rules
function add_custom_feed() {
        global $allfeeds;
        foreach ($allfeeds as $f){
            $f = preg_replace("/-/", "_", $f);
      add_action("do_feed_".$f."_feed", "create_".$f."_feed", 10, 1);
  }
  add_filter('rewrite_rules_array','customise_feed_rules');
}
add_action('init', 'add_custom_feed');



下面是一个 RSS 文件的示例:

<?php header("Content-Type: application/xml; charset=UTF-8"); echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> 
<rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
    <title>TITLE</title>
    <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    <link><?php self_link(); ?></link>
    <description>WORDPRESS_DESCRIPTION</description>
    <language><?php bloginfo_rss( 'language' ); ?></language>
    <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', current_time('mysql', 1), false); ?></pubDate>
        <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('gmt'), false); ?></lastBuildDate>
        <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
        <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
    <copyright>Copyright <?php echo mysql2date('Y', current_time('mysql', 1), false); ?>, Match&Fuse</copyright>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
        <?php $articles = get_the_posts_list( array(
                "postype"    =>    'band',
                "limit"        =>    20,
                "sortby"    =>    'post_date_gmt'
            ));
            http://www.matchandfuse.co.uk/feed/bands
        ?>
    <?php foreach ($articles as $a): ?>
    <item>
            <title><?php echo htmlspecialchars($a["title"]) ?></title>
            <link><?php echo $a["permalink"] ?></link>
            <pubDate><?php echo date('D, d M Y H:i:s +0000', $a["post_date"]); ?></pubDate>
            <?php if (strlen($a["excerpt"]) >=5 ): ?>
                <description><![CDATA[<?php echo htmlspecialchars($a["excerpt"]) ?>]]></description>
            <?php else: ?>
                <description><![CDATA[<?php echo htmlspecialchars(my_excerpt($a["content"], 100 , "words", true  )) ?>]]></description>
            <?php endif; ?>
            <content:encoded><![CDATA[<?php echo htmlspecialchars(apply_filters( 'the_content', $a["content"] )) ?>]]></content:encoded>
        </item>
        <?php endforeach; ?>
    </channel>
</rss>

PS:除了wordpress之外,我使用的是自制的查询系统,但它不应该对事情产生任何影响!

我认为问题与我称呼他们的方式有关......

rss php文件在那里:
http://www.matchandfuse.co.uk/wp/wp-content/themes/matchfuse-v1.2/feeds

非常感谢,
凯瑟 琳

找到答案?我也在使用自定义 rss 创建器脚本时遇到问题,因为我使用require('./wp-blog-header.php');使用来自WordPress的已实现数据库连接。不知何故,它干扰了WP超级缓存插件。所以我跳过了wp-blog-header.php并以普通的php方式建立与数据库的连接。工作!验证时不再有 404 错误。

相关内容

最新更新