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条)

报告相同问题?

悬赏问题

  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示