开源夏令营(7)
来源:互联网 发布:windows系统常用命令 编辑:程序博客网 时间:2024/05/21 23:00
<?php$args=array( 'post_type'=>'page',//查找出所有页面(多个结果集,复数) 'page_id'=>3//仅仅查询id号为3的页面,只有一个结果,单数);// 实例化wp_query$the_query = new WP_Query( $args );// 开始循环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 {// 如果没有找到任何结果,就输出这个}wp_reset_postdata();//不用问为什么,每次都记得写就好?>
wordpress的循环有两种类型,一种是自定义循环,一种是默认循环。
最简单的例子
Standard Loop (Alternate)
<?php // the query$the_query = new WP_Query( $args ); ?><?php if ( $the_query->have_posts() ) : ?><!-- pagination here --><!-- the loop --><?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?><h2><?php the_title(); ?></h2><?php endwhile; ?><!-- end of the loop --><!-- pagination here --><?php wp_reset_postdata(); ?><?php else : ?><p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p><?php endif; ?>
WordPress通过不同的标签获取不同的内容
0 0
- 开源夏令营(7)
- 开源夏令营(1)
- 开源夏令营(2)
- 开源夏令营(3)
- 开源夏令营(5)
- 开源夏令营(6)
- 开源夏令营(8)
- 开源夏令营之项目汇报7
- 开源夏令营(9)总结
- 开源夏令营总结
- 开源夏令营总结
- 开源夏令营总结
- 开源夏令营总结
- 开源夏令营第一周
- 开源夏令营第二周
- 开源夏令营中期报告
- 开源夏令营中期总结
- 开源夏令营中期报告
- Leetcode之 Max Points on a Line
- 开源夏令营(6)
- RocketMQ原理解析-producer 4.发送分布式事物消息
- gitbub-android-async-http框架使用
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 05.游戏界面 主角飞机的移动
- 开源夏令营(7)
- cocos2d-x 3.2 |飞机大战:碰撞与分数
- 针对main函数的运行时stack的分析
- xp system权限提升
- RocketMQ原理解析-producer 5.消息在broker落地之普通消息
- Android高版本打开网络设置界面
- RGB888和565相互转换
- 黑马程序员_iso入门基础学习_C语言day5
- hdu 1022 Train Problem I