傻大憨

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外贸建站教程分享

  在数字化时代,拥有一个强大的在线存在对于外贸业务至关重要。WordPress作为一个强大且用户友好的建站平… Continue reading WordPress外贸建站教程分享

模板之家mymoban提供的模板是否支持多语言版本

模板之家(MyMoban.com)作为一个提供网站模板的平台,可能会提供支持多语言的模板,以适应不同用户的国际… Continue reading 模板之家mymoban提供的模板是否支持多语言版本

wordpress子页面获取父页面的标题和链接

wordpress子页面获取父页面的标题和链接

wordpress搜索结果排除某个分类

从wordpress的搜索结果中排队某个分类的内容

The best WordPress service company in China

Jianzhanpress not only excels in WordPress theme design, but also has significant advantages in the field of foreign trade website construction, which can help enterprises achieve success in the international market.

WordPress外贸网站建设的关键要素与技术要点

  在全球数字化的时代,成功建站是拓展国际业务的关键一环。本文将揭示WordPress外贸网站建设的关键要素与… Continue reading WordPress外贸网站建设的关键要素与技术要点