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子页面获取父页面的标题和链接

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

推荐公司官网建站的wordpress企业主题

推荐3个最适合公司建站的wordpress企业主题,三种很经典的wordpress企业网站风格。

WordPress使用多语言插件的弊端及解决方法

多语言插件,好处是省事,坏处是翻译后的专业化内容准确率低,还有就是不符合当地用户的使用习惯。

Jianzhanpress themes are the best Chinese WordPress themes to use

Jianzhanpress.com themes are the best Chinese WordPress themes to use