WordPress获取指定数量的随机文章(不用插件)

我们希望每次打开网站时,在某个位置生成随机的文章列表,可以通过以下代码实现:

<div class="rnd_list"">
<ul style="list-style:none;">
<?php
$args = array( 'numberposts' => 6, 'orderby' => 'rand', 'post_status' => 'publish' );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>

将上面的代码复制粘贴到你需要的地方即可;它会生成6篇随机的文章。

原创内容,如需转载,请注明出处;

本文地址: https://www.perfcode.com/p/813.html

分类: 计算机技术
推荐阅读:
MATLAB使用误差扩散法进行图像半色调处理 误差扩散法(Error Diffusion)是一种常用的图像半色调处理方法,它的基本思想是通过将误差扩散到周围的像素点来逐渐逼近目标灰度值,从而实现图像半色调处理的效果。
Kali无法安装arpspoof工具的解决办法 如果你的 kali 里没有 arpspoof 工具;且使用类似于 arp-get install arpspoof 这样的命令尝试安装,但还是无法成功;那我来告诉你,你这样时无法安装成功的。
Kali更新源的方法和优质国内源 所谓的Kali源,你可以将它理解为软件仓库,系统通过它安装和更新软件;源的服务器地址写在/etc/apt/sources.list文件中;当系统使用的当前源不可用或速度不理想时,就需要更换源;
warning: implicit declaration of function 'getpid' 解决方法 在C程序中使用getpid()获取进程识别码时,可能会出现 warning: implicit declaration of function 'getpid'; did you mean 'getenv'? [-Wimplicit-function-declaration] 这样的警告信息;
C/C++程序打印输出中文导致乱码的解决方法 C/C++程序打印输出中文导致乱码的解决方法如下:
Python实现线性搜索(linear search) 比如说我有数组data,1000个元素,要从里面找x;线性搜索,就是从头找到尾,速度最慢,但是适用性最广。