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给指定ID分类添加特定的字段

wordpress给不同的分类添加特定的字段,通过编写自定义的函数就可以实现。

歪猫独立站

歪猫独立站是一个专注于跨境电商独立站建设的平台,提供多种服务和资源,帮助跨境电商卖家搭建和运营自己的独立网站。

如何在wordpress顶部header.php中引用css/bootstrap.css文件

在 WordPress 的 header.php 文件中引用 CSS 文件(如 bootstrap.css)是实现主题样式化的一种常见方式。以下是具体的步骤和代码示例

定制WordPress外贸主题需要注意的事项

定制WordPress外贸主题时,企业需要注意明确目标与定位、选择可靠的主题开发商、考虑多语言支持、优化用户体验、注重SEO优化、确保安全与稳定性、关注灵活性与可扩展性以及进行全面的测试与调试。