Home  >  Article  >  CMS Tutorial  >  How to call the latest, popular, and random articles in WordPress without plug-ins

How to call the latest, popular, and random articles in WordPress without plug-ins

藏色散人
藏色散人Original
2020-01-11 09:36:352569browse

How to call the latest, popular, and random articles in WordPress without plug-ins

#How does WordPress call the latest, popular, and random articles without plug-ins?

WordPress has no plug-in to call the latest, popular, and random article example codes

Recommended: "wordpress tutorial"

WordPress has no plug-in to call the latest, popular, and random articles. The specific implementation code is as follows. Interested friends can refer to it. I hope it will be helpful to everyone in calling news.

Call the latest Article:

The code is as follows:

<ul> 
<?php $post_query = new WP_Query(‘showposts=10′); 
while ($post_query->have_posts()) : $post_query->the_post(); 
$do_not_duplicate = $post->ID; ?> 
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li> 
<?php endwhile;?> 
</ul>

Call popular articles:

The code is as follows:

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

Call random articles:

The code is as follows :

<ul> 
<?php 
global $post; 
$postid = $post->ID; 
$args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 10); 
$query_posts = new WP_Query(); 
$query_posts->query($args); 
?> 
<?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?> 
<li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li> 
<?php endwhile; ?> 
</ul>

The above is the detailed content of How to call the latest, popular, and random articles in WordPress without plug-ins. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn