【发布时间】:2018-06-23 08:56:37
【问题描述】:
感谢大家的帮助;目前还没有任何工作,所以添加更多细节。
我在functions.php中使用下面的函数来允许我使用我自己的RSS模板,它工作正常。
add_action('init', 'customRSS');
function customRSS(){
add_feed('shows', 'customRSSFunc');
}
function customRSSFunc(){
get_template_part('rss', 'shows');
}
feed 的 php 模板是:
<?php
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
do_action( 'rss_tag_pre', 'rss2' );
?>
<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 wp_title_rss(); ?></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
$date = get_lastpostmodified( 'GMT' );
echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
?></lastBuildDate>
<language><?php bloginfo_rss( 'language' ); ?></language>
<sy:updatePeriod><?php
$duration = 'hourly';
echo apply_filters( 'rss_update_period', $duration );
?></sy:updatePeriod>
<sy:updateFrequency><?php
$frequency = '1';
echo apply_filters( 'rss_update_frequency', $frequency );
?></sy:updateFrequency>
<?php do_action( 'rss2_head'); while( have_posts()) : the_post();?>
<item>
<title><?php the_title_rss(); ?></title>
<date><?php echo customevent_get_start_date( null, false, 'd-m-Y' ); ?></date>
<time><?php echo customevent_get_start_date( null, false, 'H:i' ); ?></time>
<price><?php echo customevent_get_cost(); ?></price>
<link><?php the_permalink_rss(); ?></link>
<imageurl><?php the_post_thumbnail_url(); ?></imageurl>
<description>
<?php
$content = the_content();
echo $content ; ?>
</description>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>
我遇到问题的部分是描述 (the_content)。提要上的输出显示 p 标签等,以及在许多位置。两者都需要剥离。
我试过了:
<description>
<?php
$content = the_content();
echo wp_filter_nohtml_kses($content); ?>
</description>
和
<description>
<?php
$content = the_content();
echo strip_tags(html_entity_decode($content)); ?>
</description>
Feed 中的输出:
<description>
<p><strong>It took Michael Portillo little more than 10 years to get a seat in the Commons and then rise in power and esteem to a point where he was a favoured leader of his party and possible future PM. A track record like that suggests a privileged friend of the rich and famous ,but since leaving the house almost a decade ago Michael has endeared himself to many with his obvious respect for solid workmanship as found in our great Victorian Railways and the daily life of ordinary hard working citizens. Listen to his story, told with a “ parliamentary standup ” wit, and then feel free to question him about it. </strong></p>
<p><strong>Full Price – £19.50 </strong></p>
<p><strong>Concession – £18.50 </strong></p>
</description>
【问题讨论】:
-
您可以将 html_entity_decode() 与 strip_tags() 结合使用:
echo strip_tags(html_entity_decode($content));