我在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; ?>
我正在尝试使用以下方法清理每个帖子的 Headers :
sanitize_title(the_title());
但它根本就没有改变它 .
如果我这样做: var_dump(sanitize_title(the_title()));
它jsut返回 string(0) ""
我怎样才能在wordpress / php代码中清理 Headers ( the_title()
)?
1 回答
the_title()函数显示 Headers ,要返回它你必须使用the_title('','',false)或get_the_title() .
见doc:http://codex.wordpress.org/Function_Reference/the_title