WordPress调用某分类,并且展示其下属分类

  Wordpress          2,112 阅读          2016-01-16

最近在帮客户制作Wordpress主题,需要在首页展示一级分类,并且按照一级分类进行分组,展示子分类,万能的Wordpress是什么都能实现的!

<?php $display_categories =get_field("home_category", "option"); foreach ($display_categories as $category) { ?>
<?php query_posts("showposts=6&cat=$category")?>
<a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a>
<?php
    $categories_child = get_categories("echo=0&show_count=1&child_of=$category&title_li=&orderby=count&order=DESC&hide_empty=0&number=14");
    foreach($categories_child as $child) {
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    echo $child->cat_ID;
    echo $child->cat_name;
    echo $child->description;
    the_field('category_link', $taxonomy . '_' . $child->cat_ID);
    the_field('category_img', $taxonomy . '_' . $child->cat_ID);
    }
?>
<?php } wp_reset_query();?>

 

支付宝二维码
微信二维码

扫码打赏,您说多少就多少!

感谢您的打赏,我们会更加努力的更新站点!

发表评论