嗨,我创建了代码来显示我的wordpress主题中的节选,但是当在我的帖子中放置urls时,在我的摘录中显示它们,这是我的代码
<div class="standard-excerpt">
<?php
$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 200 );
echo $trimmed_content;
?>
<a class="text-info" href="<?php the_permalink(); ?>">
<?php _e('[Continue Reading]', 'Yallanpe Theme'); ?>
</a>
</div>我如何限制URL或链接,直到没有在我的节选中显示它们?我能用preg_match_all做这个吗?还是没有?如果我可以的话,我该怎么做呢?请修改$trimmed_content,直到不显示我的节选中的网址和链接为止。
发布于 2014-07-14 04:58:52
我想您是在寻找PHP函数strip_tags。试试这个:
<div class="standard-excerpt">
<?php
$content = strip_tags( get_the_content() );
$trimmed_content = wp_trim_words( $content , 200 );
echo $trimmed_content;
?>
<a class="text-info" href="<?php the_permalink(); ?>">
<?php _e('[Continue Reading]', 'Yallanpe Theme'); ?>
</a>
</div>注意:这不会删除<a>标记之间的单词,只需停止单击它们即可。
https://stackoverflow.com/questions/24729686
复制相似问题