WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的。用户可以在支持 PHP 和 MySQL数据库的服务器上使用自己的博客。
那么个人博客中一般会有最新、热门、随机文章等板块,网上有很多插件,但是插件用多了,会影响网站的访问速度,能不用尽量不用插件,那我在这分享下WordPress无插件调用最新、热门、随机文章,具体实现代码如下,感兴趣的朋友可以参考下哈,希望对大家在新闻调用上有所帮助

调用最新文章:
1 2 3 4 5 6
| <?php query_posts('showposts=4'); ?>
<ul class="newsList">
<?php while (have_posts()) : the_post(); ?>
<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul> |
调用热门文章:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <ul >
<?php
$post_num = 10; // 设置调用条数
$args = array(
'post_password' => '',
'post_status' => 'publish', // 只选公开的文章.
'post__not_in' => array($post->ID),//排除当前文章
'caller_get_posts' => 1, // 排除置頂文章.
'orderby' => 'comment_count', // 依評論數排序.
'posts_per_page' => $post_num
);
$query_posts = new WP_Query ();
$query_posts->query($args);
while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
<li >
<a href ="<?php the_permalink(); ?>" title ="<?php the_title(); ?>"><?php the_title (); ?></a >
</li >
<?php } wp_reset_query ();?>
</ul > |
调用随机文章:
1 2 3 4 5 6 7 8 9 10
| <ul>
<?php
$posts = get_posts('numberposts=10&orderby=rand');
foreach($posts as $post) {
setup_postdata($post);
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
}
$post = $posts[0];
?>
</ul> |
「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」