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

相关推荐

  • 常用的Rank Math SEO 中英文对照

    Basic SEO Add Focus Keyword to the SEO title.Add Focus Keyword to your SEO Meta Description.Use Focus Keyword in the URL.Use Focus Keyword at the beginning of your content.Use Focu…

    google seo 2025年9月10日
    1.8K00
  • wordpress获取分类下文章列表四种方法

    1、使用query_posts()函数以下代码实际上使用query_posts()函数调取分类目录下的文章,showposts是调取的数量。 <?php $cats = get_categories(); foreach ( $cats as $cat ) { query_posts( ‘showposts=10&cat=’ . $cat-&g…

    外贸 2025年3月22日
    1.7K00
  • wordpress 进行文章列表分页

    把以下代码放入:functions.php function lingfeng_pagenavi( $range = 4 ) { global $paged,$wp_query; if ( !$max_page ) { $max_page = $wp_query->max_num_pages; } if( $max_page >1 ) { ech…

    外贸 2025年3月22日
    1.6K00
  • wordpress开发建设常用调用代码

    1、获取页面分类列表 <?php query_posts(‘showposts=6&cat=54’); //cat=1为调用ID为1的分类下文章 while(have_posts()) : the_post(); ?> <li> <a href=”<?php echo the_permalink() ?>” …

    外贸 2025年3月22日
    1.7K00
  • WordPress主题推荐

    主题 介绍 费用 kadence Kadence 是一款由 Kadence WP 公司开发的轻量级、性能优异的 WordPress 主题,尤其适合博客、企业官网、电商网站、课程平台等多场景应用。它以“速度快、功能强、无需代码”著称,在众多建站者中口碑极佳 Kadence 是一个既适合新手也满足高级用户需求的 WordPress 主题,真正做到了“高性能 + …

    外贸 2025年5月14日
    2.6K00

发表回复

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

联系我们

在线咨询: QQ交谈

邮件:156738051@qq.com

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

关注微信