wordpress调用指定分类目录文章的方法

不过对于没有代码开发的朋友来说,在用wordpress网站制作时可能会遇到一些问题,比如调用指定分类目录下的文章,今天就教大家一个方法怎样通过代码来调用wordpress指定分类目录下的文章,以便wordpress用户能更快上手使用wordpress。

我们在wordpress 主题开发时不管是哪个页面还是分类页,可以进行如下操作

<?php 
	$posts = get_posts(array(							
		'numberposts' => '10', //输出的文章数量
		'post_type' => 'product',	//自定义文章类型名称		
		'tax_query'=>array(
			array(
				'taxonomy'=>'products', //自定义分类法名称
				'terms'=>'10' //id为64的分类。也可是多个分类array(12,64)
			)
		),
	)
	);		
?>
 
<?php if($posts): foreach($posts as $post): ?>			
	<li><a href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title();?>"><?php the_title();?></a></li>
<?php wp_reset_postdata(); endforeach; endif;?>

这样我们就可以实现在你需要的地方调用wordpress的指定分类目录下的文章了。

主题测试文章,只做测试使用。发布者:zhaolou,转转请注明出处:https://www.zhaolou.cc/archives/4233

(0)
zhaolou's avatarzhaolou
上一篇 2025年3月22日 上午10:16
下一篇 2025年3月22日 上午10:19

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

在线咨询: QQ交谈

邮件:156738051@qq.com

工作时间:周一至周五,9:00-18:00,节假日休息

关注微信