【问题标题】:I want to show the child category name not the parent category name我想显示子类别名称而不是父类别名称
【发布时间】:2012-09-18 18:52:09
【问题描述】:
  <div class="careerleft">

   <?php query_posts('cat=9&paged='.get_query_var('paged')); ?>

   <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

   <div <?php post_class() ?> id="post-<?php the_ID(); ?>">

   <p class="career">"><?php the_title(); ?></p>

   <p>Category: <?php single_cat_title()?></p>

   <p>Date posted:<?php the_time('F j, Y') ?></p>

   </div>

   <?php endwhile; ?>

   <?php else : ?>

  <h2>Not Found</h2>


  <?php endif; ?>


 </div>

我想显示子类别名称,但是当我使用 时,它只显示父类别名称。在我的类别中,父类别名称是“职业”,该类别有 3 个子类别名称,即管理、IT 相关和会计。显示子类别名称的代码是什么?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    这里你必须先提取子类别。看看如何提取Wordpress Categories

    提取父类的所有类别

    <?php $args = array( 'type' => 'post', 'parent' => 9, 'taxonomy' => 'category' );?>

    &lt;?php $categories = get_categories( $args ); ?&gt;

    提取所有类别后,创建循环以打印它们

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-03
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2015-01-01
      相关资源
      最近更新 更多