A-A+

wordpress调用指定分类下的随机文章(图文列表)

2019年05月30日 wordpress程序使用技巧分享 暂无评论 阅读 65 次

代码如下,意思很简单,相信诸君看一下就能明白了:

 

<!--  相关推荐  -->
				<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' => 6,'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>

给我留言

icon_question icon_razz icon_sad icon_evil icon_exclaim icon_smile icon_redface icon_biggrin icon_surprised icon_eek icon_confused icon_cool icon_lol icon_mad icon_twisted icon_rolleyes icon_wink icon_idea icon_arrow icon_neutral icon_cry icon_mrgreen