我在 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()));
它只是返回string(0) ""
如何清理我的 wordpress/php 代码中的标题 (the_title()
)?
最佳答案
the_title() 函数显示标题,要返回标题,您必须使用 the_title('','',false) 或 get_the_title() 。
参见文档:http://codex.wordpress.org/Function_Reference/the_title
关于php - 清理 WordPress 帖子循环中的 the_title(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35024201/