回显Wordpress函数the_title()返回表头中的值

问题描述 投票:0回答:1

我有一个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();保存帖子的每个标题。我想将这些标题值保存在表头中。我怎样才能做到这一点?

php wordpress
1个回答
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; ?>
© www.soinside.com 2019 - 2024. All rights reserved.