我有一个Wordpress查询:
$args = array('post_type' => 'food', 'posts_per_page' => 5, 'post__in' => $ids, 'post_status' => 'any', 'orderby' => 'post__in');
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
我有一个查询结果函数the_title();保存帖子的每个标题。我想将这些标题值保存在表头中。我怎么能这样做?
答案 0 :(得分:2)
从评论中可以看出这个问题:
"<thead>" the_title() "</thead>";
您需要连接转义的html标记,如下所示。注意两者之间的时期:
"<thead>" . the_title() . "</thead>";
或者你关闭php以回显你的HTML然后打开php
$args = array('post_type' => 'food', 'posts_per_page' => 5, 'post__in' => $ids, 'post_status' => 'any', 'orderby' => 'post__in');
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
/*You can escape the php by closing as below and enclose the title in php tags*/
?>
<thead><?php echo get_the_title(); ?></thead>
<?php endwhile; ?>