学课技术网
专注PHP学习资源

WordPress代码实现调用最新、热门、随机文章方法

WordPress代码实现调用最新、热门、随机文章方法 在2022-01-03 12:44 进行了更新,本站所有内容仅供大家仅供学习交流使用,请勿转载传播,严禁用于商业用途,请于24小时内删除,请支持正版!!!

很多站长咨询WordPress代码实现调用最新、热门、随机文章方法是什么?WordPress无插件调用最新、热门、随机文章,具体实现代码如下,感兴趣的朋友可以参考下。

调用最新文章:

代码如下:

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

调用热门文章:

代码如下:

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

调用随机文章:

代码如下:

<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代码实现调用最新、热门、随机文章方法的详细内容。

 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载,如果本站内容侵犯了您的个人利益,请联系QQ125252828告知。学课技术网 » WordPress代码实现调用最新、热门、随机文章方法
分享到: 更多 (0)

相关推荐

  • 暂无文章

热门文章

评论 抢沙发

评论前必须登录!

立即登录   注册

学课技术网专注软件汉化、分享、解密、绿化、Wordpress主题插件优化

联系我们技术支持
切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册