前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WordPress 在代码里调用指定分类下随机文章列表 (图文列表)

WordPress 在代码里调用指定分类下随机文章列表 (图文列表)

作者头像
AlexTao
修改2023-05-16 13:09:46
8180
修改2023-05-16 13:09:46
举报
文章被收录于专栏:钻芒博客钻芒博客

在调用位置插入即可

有图列表:

代码语言:javascript
复制
<!--  相关推荐  -->
				<div id="Recommend">
					<h2 id="Recommend_title">
						相关推荐:
					</h2>
					<div id="Recommend_list">
						<ul>
							<?php $cat = get_the_category();
foreach($cat as $key=>$category) {
	$catid = $category->term_id;
}
$args = array('orderby' => 'rand','showposts' => 15,'cat' => $catid );
$query_posts = new WP_Query();
$query_posts->query($args);
while ($query_posts->have_posts()) : $query_posts->the_post();
?>
							<li>
								<a href="<?php the_permalink();?>" class="Recommend_image" title="点击查看作品[<?php the_title();?>] 详情">
									<img src="<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>" alt="作品[<?php the_title();?>]<?php echo wp_trim_words( get_the_excerpt(), 40 ); ?>"  style="width:400px;height:200px;" />
								</a>
								<h2 class="Recommend_entrytitle">
									<a href="<?php the_permalink(); ?>"><?php the_title();
?></a>
								</h2>
							</li>
							<?php endwhile;
?>
							<?php wp_reset_query();
?>
						</ul>
					</div>
				</div>

无图列表:

代码语言:javascript
复制
    <?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; ?>

百度未收录

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-02-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 在调用位置插入即可
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档