百度
360搜索
搜狗搜索

WordPress无插件调用最新、热门、随机文章实例代码详细介绍

WordPress无插件调用最新、热门、随机文章,具体实现代码如下,感兴趣的朋友可以参考下哈,希望对大家在新闻调用上有所帮助

调用最新文章:

代码如下:

<ul>

<? $post_query = new _Query(‘showposts=10&
prime;);

while ($post_query->have_posts()) : $post_query->the_post();

$do_not_duplicate = $post->ID; ?>

<li><a href=”&l
t;?php the_permalink(); ?>”><?php the_title(); ?></a></li>

<?php enhile;?>

</ul>

调用热门文章:

代码如下:

<ul>

<?php

$post_num = 10; // 设置调用条数

$args = array(

‘post_password’ => ”,

‘post_status’ => ‘publish’, // 只选公开的文章.

‘post__not_in’ => ar
ray($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>

调用随机文章:

代码如下:

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

本文标题: WordPress无插件调用最新、热门、随机文章实例代码 ,

网站数据信息

"WordPress无插件调用最新、热门、随机文章实例代码"浏览人数已经达到43次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:WordPress无插件调用最新、热门、随机文章实例代码的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!