Wordpress自定义RSS:第6行第2行的错误:仅在文档开头允许XML声明

问题描述 投票:0回答:1

我在WordPress中创建了一个自定义rss源,我插入了以下代码:

<?php
/**
 * Template Name: Custom RSS Template - Feedname
 */
$postCount = 5; // The number of posts to show in the feed
$posts = query_posts('showposts=' . $postCount);
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<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/"
        <?php do_action('rss2_ns'); ?>>
<channel>
        <title><?php bloginfo_rss('name'); ?> - Feed</title>
        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
        <link><?php bloginfo_rss('url') ?></link>
        <description><?php bloginfo_rss('description') ?></description>
        <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
        <language><?php echo get_option('rss_language'); ?></language>
        <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
        <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
        <?php do_action('rss2_head'); ?>
        <?php while(have_posts()) : the_post(); ?>
                <item>
                        <title><?php the_title_rss(); ?></title>
                        <link><?php the_permalink_rss(); ?></link>
                        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
                        <dc:creator><?php the_author(); ?></dc:creator>
                        <?php the_category_rss() ?>
                        <guid isPermaLink="false"><?php the_guid(); ?></guid>
                        <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
                        <content:encoded><![CDATA[<?php $categories = get_the_category_rss();
                                $containNews = false;
                                if (stripos($categories, "Newsletter") !== false) {
                                        $containNews = true;
                                }
                                if ($containNews) {
                                    the_content_feed();
                                } else {
                                    the_excerpt_rss();
                                }; ?>]]>
                        </content:encoded>
                        <?php rss_enclosure(); ?>
                        <?php do_action('rss2_item'); ?>
                </item>
        <?php endwhile; ?>
</channel>
</rss>

我不是php和xml的专家,我只使用这里提供的代码:http://www.wpbeginner.com/wp-tutorials/how-to-create-custom-rss-feeds-in-wordpress/

当我打开自定义页面时,出现以下错误:

此页面包含以下错误:第6行第2行的错误:仅在文档开头允许的XML声明下面是第一个错误之前的页面呈现。

问题是什么?我该如何解决这个问题?

非常感谢

问候

伊万

php wordpress rss
1个回答
0
投票

我实际上发现有一个插件导致了这个问题......

我继续禁用所有插件并逐个重新启用...

我将跟进插件开发人员,看看有什么问题......

© www.soinside.com 2019 - 2024. All rights reserved.