wordpress 调用栏目集合
导航调取二级分类和二级分类下的产品
<?php
                                
                                    $categories =  get_categories('child_of=2&depth=0&hide_empty=0');   
                                    foreach ($categories as $category) {  
                                        $now_cat = $category->term_id;
                                        $cat_name = $category->cat_name;
                                ?> 
                      <div class="menu_down_clm">
                      <a class="menu_down_clm_tt" href="<?php echo get_category_link($category); ?>" title="<?php echo $cat_name; ?>">
                        <?php echo $cat_name; ?>
                      </a>  
                      <div class="menu_down_clm_down">
                          


                      		<?php
                                            $args = array(
                                            'post_type' => 'post',
                                            'showposts' => 100,
                                            
                                            'cat' => array($now_cat),//指定分类id
                                            );
                                        ?>
                                        <?php
                                            $catquery = new WP_Query($args);
                                            while($catquery->have_posts()) : $catquery->the_post();
                                            
                                        ?>
                                    <a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_title();?></a>
                                    <?php endwhile; wp_reset_query();?>


                      </div>
                    </div>
                      <?php }?>



wp 调取指定一级栏目的二级分类

<?php
                            $a=get_category_root_id(1);
                            $args=array(
                            'orderby'    => 'id',
                            'hide_empty' => "0",
                            'child_of' => $a,//可以换为:'child_of' => '1', // 这个参数是什么,还在确认。
                            );
                            $categories=get_categories($args);
                            foreach($categories as $category) {
                        ?>
                        <a href="<?php echo get_category_link( $category->term_id )  ?> ">
                           <?php echo get_the_category_by_ID( $category->term_id ) ?>
                        </a>
                        <?php }?>   



wp 调取二级分类下的三级类

<?php
                                    
                                        $categories =  get_categories('child_of=1&depth=0&hide_empty=0&orderby=id&order=asc');   
                                        foreach ($categories as $category) {  
                                            $now_cat = $category->term_id;
                                            $cat_name = $category->cat_name;
                                            $cat_id = $category->cat_ID;
                                    ?> 
                            <a href="<?php echo get_category_link($category); ?>" title="<?php echo $cat_name; ?>" id="nav_<?php echo $cat_id; ?>">
                                <div class="icon iconfont icon-jia"></div>
                                <div class="tt">
                                    <?php echo $cat_name; ?>
                                </div>
                            </a>

 <?php $categories2 =  get_categories("parent=$cat_id&depth=0&hide_empty=0&orderby=id&order=asc"); 
    foreach ($categories2 as $category2) {
    $cat_name = $category2->cat_name;
?>
<a href="<?php echo get_category_link($category2); ?>" title="<?php echo $cat_name; ?>">
    <?php echo $cat_name; ?>
</a>
<?php }?>


                            <?php }?>


wordpress 调取二级和二级下分类的方法

<?php wp_list_cats('sort_column=name&optioncount=0&hierarchical=1&hide_empty=0&child_of=1'); ?>


调取所有二级的方法


<?php
                                
                            $categories =  get_categories('child_of=1&depth=0&hide_empty=0&orderby=id&order=asc');   
                            foreach ($categories as $category) {  
                                $now_cat = $category->term_id;
                                $cat_name = $category->cat_name;
                                $cat_id = $category->cat_ID;
                        ?> 
                            <li id="nav_<?php echo $cat_id; ?>">
    						<a href="<?php echo get_category_link($category); ?>" title="<?php echo $cat_name; ?>" ><?php echo $cat_name; ?> ></a>
    						</li>
						<?php }?>

评论

  1. 李二狗

    你好啊

    1年前
    2022-10-25 10:48:07
    • lzf 博主

      谢谢你的评论

      1年前
      2022-10-25 10:50:01

发送评论 编辑评论


				
上一篇
下一篇