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 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料