感谢所有的帮助;没有任何工作,所以添加更多的细节。
我正在使用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)。 Feed上的输出显示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>
答案 0 :(得分:1)
使用这个。
wp_filter_nohtml_kses( string $data );
检查此链接。 https://developer.wordpress.org/reference/functions/wp_filter_nohtml_kses/
答案 1 :(得分:0)
您可以使用strip_tags包装str_replace,如下所示:
<?php
function the_content(){
echo '<p> Content</p>';
}
$content = the_content();
echo str_replace(' ','',strip_tags($content));
?>
我测试过这个并且工作正常。如果这不适合您,请告诉您功能的内容吗?
修改强>
我还建议您在这里查看html_entity_decode:
https://www.w3schools.com/php/func_string_html_entity_decode.asp
这是实现您想要的最佳方式。我上面的答案是直接回答你的要求,但这是更好的选择。