0
我有新闻聚合器的自定义RSS模板。是否可以从the_content_feed();
中排除所有媒体文件,如图像/视频? 我需要显示一个纯文本。如何从Wordpress RSS源中排除媒体文件?
这里是我的模板
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$frequency = 1;
$duration = 'hourly';
$postimages = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'large');
if ($postimages) {
$postimage = $postimages[0];
} else {
$postimage = get_stylesheet_directory_uri() . '/images/default.jpg';
}
echo '<?xml version="1.0" encoding="UTF-8"?>' ."\r\n"; ?>
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss('description') ?></description>
<yandex:logo></yandex:logo>
<yandex:logo type="square"></yandex:logo>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0200', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language><?php bloginfo_rss('language'); ?></language>
<?php do_action('rss2_head'); ?>
<?php while(have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss(); ?></title>
<link><?php the_permalink_rss(); ?></link>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<author><?php the_author(); ?></author>
<enclosure url="<?php echo esc_url($postimage); ?>" type="image/jpeg" />
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0200', get_date_from_gmt(get_post_time('Y-m-d H:i:s', true)), false); ?></pubDate>
<description>
<![CDATA[<?php the_excerpt_rss(); ?>]]>
</description>
<yandex:full-text>
<![CDATA[<?php the_content_feed(); ?>]]>
</yandex:full-text>
</item>
<?php endwhile; ?>
</channel>
</rss>
我试图使用此过滤器,但没有运气:(
add_filter("the_content_feed", "excludeimg") ;
function excludeimg($content) {
$content = preg_replace('#(<img.*?>).*?(/>)#', '$1$2', $content);
return $content;
}
?>
虽然这段代码可能会回答这个问题,但最好包含一些_context_,解释_how_它的工作原理和_when_使用它。从长远来看,仅有代码的答案是没有用的。 –