the_title not working

时间:2014-10-27 作者:Jaeeun Lee

我正在使用the_title() 显示自定义帖子类型的标题,但它不起作用;标题不显示。

get_header();
$wp_query = new WP_Query();
$wp_query -> query(\'post_type=press&showposts=20\');
while ($wp_query->have_posts()) : 
    $wp_query->the_post(); ?>
    <div class="press-item">
        <div class="press-img"><?php the_post_thumbnail(\'medium\');?></div>
        <div class="press-content">
            <div class="press-title"><?php the_title(); ?> </div>
            <div class="press-excerpt"><?php the_excerpt(); ?> </div>
        </div>
    </div>
<?php endwhile;
get_footer();

1 个回复
最合适的回答,由SO网友:shanebp 整理而成

尝试以下查询:

$args = array(
    \'post_type\'      => \'press\',
    \'posts_per_page\' => 20
);

$wp_query = new WP_Query( $args );

while // etc. 
您也可以尝试:

<div class="press-title"><?php echo get_the_title(); ?> </div>

结束

相关推荐