#php #xml #wordpress #rss
Вопрос:
Я пытаюсь создать пользовательский XML-RSS-канал. Однако мой код работает не совсем так, как ожидалось. Вот что я сделал:
В functions.php Я создал ленту под названием «топ».:
add_action('init', 'customRSS');
function customRSS(){
add_feed('feedname', 'top');
get_template_part('rss', 'top');
}
В моей дочерней теме я создал файл rss-top.php который содержит мой файл шаблона.
Я ищу довольно простую структуру шаблона, как показано ниже:
<?xml version="1.0" encoding="UTF-8"?>
<articles>
<article>
<title>Overskrift</title>
<teaser>Short excerpt</teaser>d
<link>http://link-to-post.com/</link>
<image>http://placehold.it/100x100</image>
<date>19-06-2017 11:21:00</date>
</article>
<article>
<title>Overskrift</title>
<teaser>Short excerpt</teaser>
<link>http://link-to-post.com/</link>
<image>http://placehold.it/100x100</image>
<date>19-06-2017 11:21:00</date>
</article>
</articles>
Я попытался создать структуру примерно так:
<?php
/**
* Template Name: Custom RSS Template - top
*/
$postCount = 6; // 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').'"?'.'>';
?>
<articles>
<?php while(have_posts()) : the_post(); ?>
<article>
<title><?php the_title_rss(); ?></title>
<teaser><![CDATA[<?php the_excerpt_rss() ?>]]></teaser>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<link><?php the_permalink_rss(); ?></link>
<image><?php get_the_post_thumbnail( $post->ID ); ?></image>
<date><?php echo mysql2date('D, d M Y H:i:s 0000', get_post_time('Y-m-d H:i:s', true), false); ?></date>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</article>
<?php endwhile; ?>
</articles>
После этого я обновил постоянную ссылку, а затем попытался просмотреть site.com/rss/top.xml
Однако по какой-то причине он просто показывает последние пару сообщений, как будто это была страница архива на моем сайте, а не как XML-файл, как ожидалось. Есть какие-нибудь указания на то, чего мне может не хватать ??