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 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络