php - 清理 WordPress 帖子循环中的 the_title()

标签 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()));

它只是返回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/

相关文章:

php - 使用自定义日期检索最近 3 年的数据

php - 将 js 添加到 wordpress 以实现 css activemenu 高亮显示

php - 如何在 Drupal 中进行绝对重定向?

带有upload_files true但edit_post false的Wordpress自定义用户角色,我如何删除和编辑媒体?

php - 如何按分类术语从自定义 WordPress MySQL 查询中排除结果

PHP 和 Elasticsearch 在返回的对象中包含分数/相关性

php - 用php显示mysql表

javascript - 选择具有随机类的 div

CSS 在某些页面上有效但在其他页面上无效?

php - 如何修复此错误 XML 解析错误 : not well-formed