duandou8457 2015-02-23 14:53
浏览 7
已采纳

WP查询,获取模板

I have created a query to return 3 particular posts however at the moment they just appear with the three titles in a list as per the query on WP Codex.

I need them to show as per the blog section but am unsure as to where and how to call the template in. This is my code:

<?php

// The Query
$include_ids = array( '114', '115', '116' );
$query = new WP_Query( array( 'post__in' => $include_ids ) );

// The Loop
if ( $query->have_posts() ) {
    echo '<ul>';
    while ( $query->have_posts() ) {
        $query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
}

?>

Can anyone help me with this please?

  • 写回答

2条回答 默认 最新

  • duanbo6871 2015-02-23 16:29
    关注

    You need to include the code to actually include the template you need. The details depend a bit on the theme, but is probably going to be something like:

    <?php if ( $query->have_posts() )  : ?>
        <?php while ( $query->have_posts() ) : ?>
            <?php $query->the_post(); ?>
            <?php get_template_part('content', get_post_format()); ?>
        <?php endwhile; ?>
    <?php endif; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?