WP_Query
是wordpress提供的一个类,它支持的参数非常完善灵活,博主通过WP_Query
类可以创建自己所需要的wordpress循环输出,比如调用最新文章、热门文章、自定义文章类型文章循环输出等,和query_posts()
函数具有相同的查询功能,但优于query_posts()
函数。
wordpress使用WP_Query函数实现最新n条文章:
<?php
$post_query = new WP_Query('showposts=10');
while($post_query->have_posts()) : $post_query->the_post();
$do_not_duplicate = $post_ID;?>
<li class="media">
<div class='media-header'>
<img src="static/picture/u=3860383438,3596170004&fm=26&gp=0.jpg" height='150' width='250' class="mr-3 d-none d-sm-block" alt="...">
<div class='tags' style='width:97%'>
<span><span class='text-warning'> </span>前端</span>
<time><span class='text-primary'> </span><?php the_time('Y-m-d H:i:s')?></time>
<span><span class='text-secondary'> </span>浏览(0)</span>
<span><span class='text-info'> </span><?php the_author()?></span>
<span class='float-right '><a href="<?php the_permalink()?>" class='text-success'>++阅读原文</a></span>
</div>
</div>
<div class="media-body">
<h5 class="mt-0 mb-1 h5"><?php the_title();?></h5>
<?php the_content();?>
</div>
</li>
<?php endwhile;?>