傻大憨

wordpress子分类调用父分类名称和链接

专为导航而生,在wordpress模板制作过程中常常会在做breadcrumbs导航时会用到,子分类调用父分类的名称和链接,下面这段简洁的代码,可以完美解决这个问题。

<?php echo get_category_parents( $cat, true, ' &raquo; ' ); ?>

下面这种方法也可以,不过代码不够简洁。

<?php
if ( is_category() ) {
    // Get the current category term id.
    $query_obj = get_queried_object();
    $term_id   = $query_obj->term_id;
 
    echo get_term_parents_list( $term_id, 'category' );
}
?>

第三种方法,调用分类目录名称和链接,作为导航。

<?php
if ( ( is_tax() || is_category() || is_tag() ) ) {
    $trail     = '';
    $home      = '/<a href="' . get_home_url() . '">Home</a>';
    $query_obj = get_queried_object();
    $term_id   = $query_obj->term_id;
    $taxonomy  = get_taxonomy( $query_obj->taxonomy );
 
    if ( $term_id && $taxonomy ) {
        // Add taxonomy label name to the trail.
       // $trail .=  '/' . $taxonomy->labels->menu_name;
        // Add term parents to the trail.
        $trail .= '/' . get_term_parents_list( $term_id, $taxonomy->name, array( 'inclusive' => false ) );
    }
 
    // Print trail and add current term name at the end.
    echo '<p class="breadcrumb-trail">' . $home . $trail . $query_obj->name . '</p>';
}
?>
Published
Categorized as 建站知识 Tagged ,

By 傻大憨

shadahan.com是一个关注跨境电商、创业话题的网站。

怎么选择一个靠谱的wordpress建站公司

拥有一个功能强大、设计精美的网站对于企业来说至关重要。无论是展示品牌形象、推广产品,还是与客户互动,网站都是企… Continue reading 怎么选择一个靠谱的wordpress建站公司

外贸SOHO低成本建站 1000预算建网站方案

搞清楚这些建站相关的知识和建站的流程步骤,外贸SOHO可以用1000元左右的预算搭建一个功能齐全且具有吸引力的网站。

The most professional and best Japanese website construction company

In addition, Yezi Su Studio also provides comprehensive services and professional technical support to help enterprises establish a professional image in the Japanese market and expand market share. Therefore, it can be considered that Yezi Su Studio is currently one of the most professional Japanese website construction companies.

跨境电商独立站建的真实费用

跨境电商独立站建的真实费用是多少,看了这个明细,就一目了然了。

WordPress外贸建站平台在行业的领先地位

  WordPress外贸建站平台一直以其卓越的灵活性、丰富的功能和用户友好的界面而在全球范围内备受青睐。本文… Continue reading WordPress外贸建站平台在行业的领先地位

阿拉伯语网站建设成本分析与建站方案选择指南

随着”一带一路”倡议的深入推进,中国与阿拉伯世界的贸易往来日益频繁,越来越多中国企业选择拓展中东市场。建阿拉伯语网站,成为了做好中东市场的第一步。