duanleiming2014 2014-09-30 08:38
浏览 36
已采纳

如何在子类别页面中显示Wordpress类别?

Ok so let me start off by telling you my goal then you can look at the example below which will make more sense. I am trying to achieve a simple filter with categories so to speak. I am creating a simple custom post type named "Cars" and it will have a field for an image and description of all cars. Now I am displaying that custom post type through a loop and filtering them by assigning them to specific categories and displaying them in the category.php through conditionals.

So I have a Category of HONDA and 3 Sub-Categories of that category:

  • Accord
  • Civic
  • Prelude

Now when I am on the "Cars" Page it will display ALL Categories custom post type and on the left hand side there will be a sidebar with all the categories of CARS such as HONDA - TOYOTA - NISSA

When I click on a category which is a car make in the left it will display all the custom post types that are assigned to that specific category and on the sidebar where the categories displayed now it will only display HONDA categories and it's Sub-Categories

NOW THE PROBLEM IS: When I click on a HONDA sub-category such as Accord the sidebar displaying all the car categories related to that sub-cat does not display any more when it should.

CLICK HERE FOR THE EXAMPLE (this should make everything a lot more clear)

And here is the logic I am using to filter what categories display on the sidebar depending on what category it is in.

<?php if (is_category('Honda') ) : ?>

    <?php $args = array(
    'orderby'            => 'name',
    'order'              => 'ASC',
    'style'              => 'list',
    'show_count'         => 1,
    'hide_empty'         => 1,
    'use_desc_for_title' => 1,
    'child_of'           => 5,
    'hierarchical'       => 1,
    'title_li'           => __( 'Categories' ),
    'show_option_none'   => __( 'No categories' ),
    'number'             => null,
    'echo'               => 1,
    'taxonomy'           => 'category',
    'walker'             => null
); ?>

<?php wp_list_categories( $args ); ?>

<?php else : ?>
<p>This is some generic text to describe all other category pages.</p>
<?php endif; ?>
  • 写回答

1条回答 默认 最新

  • doumingo04696 2014-09-30 08:44
    关注

    There is also the Wordpress function in_category

    http://codex.wordpress.org/Function_Reference/in_category

    So your code should look something like this:

    <?php if (is_category('Honda') || in_category('Honda') ) : ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用