1、wordpress随机获取文章10篇文章,轻松实现wordpress文章的随机调用;
<?php
$rand_posts = get_posts('numberposts=10&orderby=rand');
foreach($rand_posts as $post):
?>
<!–下面是你想自定义的Loop–>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;?>
2、获取wordpress文章的相关文章代码:
//获取相关文章
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>10,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href='<?php the_permalink() ?>' rel='bookmark'
title='<?php the_title_attribute(); ?>'><?php the_title();?>
<?php comments_number(' ','(1)','(%)'); ?></a></li>
<?php
endwhile;
}
}
wp_reset_query();
?>
本文分享自 wordpress建站吧 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有