WordPress只显示“子子类别”,而不显示父子

时间:2018-12-18 11:24:35

标签: php wordpress categories wp-list-categories

我尝试建立第一个主题为classiera的wordpress网站,但是我遇到了问题,需要帮助。

我的wordpress有:

Parent Category > Sub Category > Sub-Sub Category

我的源代码:

<?php 
global $redux_demo;
$classieraIconsStyle = $redux_demo['classiera_cat_icon_img'];
$classieraCurrencyTag = $redux_demo['classierapostcurrency'];
$primaryColor = $redux_demo['color-primary'];
$category_icon_code = "";
$category_icon_color = "";
$catIcon = "";
$allCatURL = classiera_get_template_url('template-all-categories.php'); 
global $post;
$category = get_the_category();
$catID = $category[0]->cat_ID;
if ($category[0]->category_parent == 0) {
    $tag = $category[0]->cat_ID;
    $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
    if (isset($tag_extra_fields[$tag])) {
        $category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
        $category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
        $classieraCatIcoIMG = $tag_extra_fields[$tag]['your_image_url'];
    }
}elseif(isset($category[1]->category_parent) && $category[1]->category_parent == 0){
    $tag = $category[0]->category_parent;
    $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
    if (isset($tag_extra_fields[$tag])) {
        $category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
        $category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
        $classieraCatIcoIMG = $tag_extra_fields[$tag]['your_image_url'];
    }
}else{
    $tag = $category[0]->category_parent;
    $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
    if (isset($tag_extra_fields[$tag])) {
        $category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
        $category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
        $classieraCatIcoIMG = $tag_extra_fields[$tag]['your_image_url'];
    }
}
if(!empty($category_icon_code)) {
    $category_icon = stripslashes($category_icon_code);
}   
if(empty($category_icon_color)) {
    $category_icon_color = $primaryColor;
}

$post_price = get_post_meta($post->ID, 'post_price', true);
$theTitle = get_the_title();
$postCatgory = get_the_category( $post->ID );                           
$categoryLink = get_category_link($catID);
$classiera_ads_type = get_post_meta($post->ID, 'classiera_ads_type', true);
$post_currency_tag = get_post_meta($post->ID, 'post_currency_tag', true);
$post_phone = get_post_meta($post->ID, 'post_phone', true);
$post_location = get_post_meta($post->ID, 'post_location', true);
$post_state = get_post_meta($post->ID, 'post_state', true);
$post_city = get_post_meta($post->ID, 'post_city', true);   
$featured_post = get_post_meta($post->ID, 'featured_post', true);
$classieraPostAuthor = $post->post_author;
$classieraAuthorEmail = get_the_author_meta('user_email', $classieraPostAuthor);    ?>

这是我们显示类别的回声

            </p>
                <span><i class="<?php echo esc_attr( $category_icon_code ); ?>" style="color:#ff000"></i>&nbsp;<a href="<?php echo esc_url( $categoryLink ); ?>"> <?php echo esc_html( $postCatgory[0]->name ); ?></a></span>
                &nbsp;&nbsp;&nbsp;
                <span><i class="fas fa-map-marker-alt" style="color:#ff000"></i>&nbsp;<?php echo esc_attr($post_state); ?></span>
            </p>

这是这样的节目:

x

图中显示“ MOBIL”为子类别 如何将“子类别”更改为“子子类别”?

0 个答案:

没有答案