在如今的WordPress主题搞得越强大越受欢迎,这个好像已经成了现在WordPress的爱好者的喜好,如果你也要加入战圈,所以要具备很多WordPress知识以及相关经验,那么今天咱们来个小课程分享就是WordPress在开发中调用指定多个分类方法。
虽然对于老鸟来说不算什么但是最近有朋友问我WordPress如何调用多个指定分类?因为他要在后台框架主题设置中加入幻灯片调取多个指定分类来变化幻灯片,这里呢瑞课给出了以下代码。
后台主题设置版
<?php
$categories = explode(",",ruikeme( 'ruikeme_slide_fenlei' ));//ID传递,逗号抽取
$num = ruikeme('ruikeme_slide_number');//篇数
$order = ruikeme('ruikeme_slide_order');//排序
$args = array( 'cat' => $categories,'posts_per_page' => $num,'orderby' => 'title','order' => '$order');
query_posts($args);while (have_posts()) : the_post();?>
<li><a href="<?php the_permalink(); ?>" rel="external nofollow" rel="external nofollow" ><img src="<?php echo post_thumbnail_src(); ?>" alt="<?php the_title();?>" /><?php the_title();?></a></li>
<?php endwhile; wp_reset_query();?>
简单直接调用版
<?php
//1,3为分类ID 2为数量调用几篇
$args = array( 'category__and' => array(1,3), 'posts_per_page' => 2, 'orderby' => 'title', 'order' => 'DESC' ) ;
query_posts($args);while (have_posts()) : the_post();?>
<li><a href="<?php the_permalink(); ?>" rel="external nofollow" rel="external nofollow" ><img src="<?php echo post_thumbnail_src(); ?>" alt="<?php the_title();?>" /><?php the_title();?></a></li>
<?php endwhile; wp_reset_query();?>
OK今天的WordPress调用指定多个分类教程到此结束有问题随时可以找我讨论。