首页 > 其他 > 详细

WordPress主题制作教程5:循环

时间:2015-04-08 10:33:35      阅读:158      评论:0      收藏:0      [点我收藏+]

调用所有页面,post_type值:page对应页面,post对应文章

<?php
$args=array(
  ‘post_type‘=>‘page‘ 
);

$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
    echo ‘<ul>‘;
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo ‘<li>‘ . get_the_title() . ‘</li>‘;
    }
    echo ‘</ul>‘;
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>

调用多id内容,参数修改为:

$args=array(
‘post_type‘=>‘page‘ ,
‘page_id=2,86‘
);

调用指定id内容,参数修改为:

$args=array(
 ‘post_type‘=>‘page‘ ,
‘page_id‘=>2
);

 

 想知道怎么在循环内调用其他内容,请看:

WordPress主题制作教程6:常用模版标签

 

查看wordpress的WP_Query文档

WordPress主题制作教程5:循环

原文:http://www.cnblogs.com/tinyphp/p/4399855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!