傻大憨

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获取父页面的2种方法

wordpress模板制作的过程中有时会用到获取父页面的ID,下面是wordpress获取父页面的2种方法。

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网站文章时间格式改为“几分钟前”

刚才访问一个网站时,发现这个网站文章发布时间并不是直接显示为具体时间,而是显示为“几分钟前”,大半夜的,不可能那么多文章都是几分钟前发布的,于是找了一下相关的教程,发现要实现这个挺简单的。

为什么有些主题不支持elementor?

elementor是wordpress的一个第三方的插件,不是所有的wordpress主题,都必须要支持elementor

建一个外贸独立站大约多少钱

外贸独立站因为独特的优势,越来越被做外贸的跨境电商所青睐。简站主题经常接到做外贸的老板咨询,建一个wordpr… Continue reading 建一个外贸独立站大约多少钱

纯代码实现给WordPress添加文章复制功能

把下面一段代码添加到functions.php文件中,就可以实现文章复制功能。