在wordpress帖子循环中清理the_title()

时间:2016-01-26 21:20:50

标签: php wordpress

我在wordpress中使用while循环,我想创建自己的帖子链接:

<?php $query = new WP_Query( array('post_type' => 'knowledgebase', 'posts_per_page' => 20, 'knowledgebase-categories' => $var_id ) ); ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="/knowledgebase/article/"><?php sanitize_title(the_title()); ?></a>
</article> <!-- .et_pb_post -->
<?php endwhile; ?>

我正在尝试使用以下方式清理每个帖子的标题:

sanitize_title(the_title());

但它根本就没有改变它。

如果我这样做:var_dump(sanitize_title(the_title()));

它jsut返回string(0) ""

如何在wordpress / php代码中清理标题(the_title())?

1 个答案:

答案 0 :(得分:2)

the_title()函数显示标题,返回它必须使用the_title('','',false)或get_the_title()。

请参阅doc:http://codex.wordpress.org/Function_Reference/the_title

相关问题