【问题标题】:How to show diff products and subcategory on custom taxonomy template?如何在自定义分类模板上显示差异产品和子类别?
【发布时间】:2016-05-19 18:29:09
【问题描述】:

我在管理员中创建了名为 testimonial 的自定义帖子类型,并在分类中创建了名为 sesseion 的分类。我在分类中有多个类别和子猫。我在主页上显示所有父猫和子猫。当用户点击子猫时需要显示该子类别的所有产品,当用户点击父类别时,它需要显示所有子类别列表。

我创建了一个名为“taxonomy-sesseion”的自定义模板。但是当我点击父目录和子目录时,它会重定向到该模板。我是否需要在同一个模板上添加一个条件以根据父目录显示差异列表和子猫?

这是在自定义分类模板上获取产品列表的代码。

$posts_array =
    array(
        'posts_per_page' => 16,
        'post_type' => 'testimonials',
        'tax_query' => array(
            array(
                'taxonomy' => 'sessions',
                'field' => 'term_id',
                'terms' => $term->term_id,
            )
        )
    );
$query = new WP_Query($posts_array); 

if ($query->have_posts()) : 

while ($query->have_posts()) : $query->the_post(); 
$thumb_id = get_post_thumbnail_id($max_value[$i]->post_id);
$thumb_url = wp_get_attachment_image_src($thumb_id, 'large', true);

endwhile; 

else:
echo "No Record";   

endif;

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您可以将子类别重定向到另一个模板,例如“sesseion-index.php”

    global $wp_query;
    $taxonomy = $wp_query->get_queried_object();
    if ( $taxonomy->parent!=0 ) {
        // do required actions
        include(TEMPLATEPATH .'/sesseion-index.php');
    }else {
    get_header();
    //etc.
    get_footer();
    

    将此代码添加到“taxonomy-sesseion.php”,您可以在那里显示子类别列表和“sesseion-index.php”上的推荐。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 2021-07-30
      • 1970-01-01
      • 2013-03-10
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多