SOHO创业

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 SOHO

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

WordPress外贸建站模板选择:关键因素与详细分析

在当今全球化的商业环境中,外贸建站已成为企业拓展国际市场、提升品牌形象、增强竞争力的关键手段。WordPress作为一款功能强大、易于使用的建站平台,受到了众多外贸企业的青睐。

wordpress建站费用明细

WordPress建站的主要费用包括域名、托管、主题、插件和其他相关费用,如SSL等。‌

wordpress禁用xmlrpc

将以下代码插入到functions.php文件中即可

买WordPress主题自己搭建网站需要注意些什么

在选择和购买WordPress主题时,有很多需要注意的地方,以确保自己的网站能够顺利搭建并正常运行。

为什么说GGD模式“最靠谱”

GGD独立站模式为跨境电商卖家提供了一种高效、精准且灵活的运营推广方式,通过充分利用Google生态系统的资源和工具,能够有效提升独立站的运营效果和市场竞争力。

通过PHPMyAdmin导入WP数据库文件的步骤

wordpress通过phpmyadmin导入数据库文件.sql的步骤与过程中发生的常见错误