免费《新手做网站视频教程》,在线观看,如果你想从零开始自己做网站,点击开始吧!

WordPress分类页获取所有分类名

  1. 首页
  2. »
  3. 图文教程
  4. »
  5. WordPress建站教程
  6. »
  7. WordPress分类页获取所有分类名

文章目录

category.php页

<?php
                    // 获取全站分类名称和url(分类中必须含有文章,否则不显示)
                    $args = array(
                        'orderby' => 'ID',
                        'exclude' => '1',       //排除的分类ID,以英文逗号分隔开
                        'order' => 'ASC'
                    );
                    $categories = get_categories($args);
                    foreach ($categories as $category) {
                        echo '<li style="z-index:2;" class="wp_subtop" pid="1"><a class="  " href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
                    }
                    ?>

taxonomy

<?php
                                // 获取全站分类名称和url(分类中必须含有文章,否则不显示)
                                $args = array(
                                    'orderby'   =>  'ID',
                                    'exclude'   =>  '1',        // 排除的分类ID,以英文逗号分隔开
                                    'order'     =>  'ASC',
                                    'taxonomy'  =>  'news_list' // 自定义文章类型
                                );
                                $categories = get_categories($args);
                                foreach ($categories as $category) {
                                    echo '<li style="z-index:2;" class="wp_subtop" pid="1"><a class="  " href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
                                }
                                ?>

推荐阅读

联系我