1

我写在这里是因为我为我的 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之外的自制查询系统,但它不应该对这个东西有任何影响!

我认为问题与我称呼他们的方式有关……</p>

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

非常感谢,
凯瑟琳

4

1 回答 1

0

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

于 2013-03-18T17:34:29.263 回答