【问题标题】:How to display Woocommerce category description with DIVI theme如何使用 DIVI 主题显示 Woocommerce 类别描述
【发布时间】:2021-05-18 14:28:23
【问题描述】:

我正在使用 DIVI 主题并创建了自定义类别布局。但是,我似乎找不到将类别描述添加到布局的方法。 DIVI 没有提供任何答案,我也在这里搜索过。我可以使用一些标签来获取它吗?

下面的代码几乎可以工作 - 我确实得到了文本,但没有换行符,即使它们在我执行 echo '<pre>'; print_r($cat); echo '</pre>'; 时出现

add_shortcode('cat_desc', 'cat_desc_shortcode');
function cat_desc_shortcode() {
    
    global $wp_query;
    $cat = $wp_query->get_queried_object();
        
    if( $cat == null ) return;

    $output = '<div class="page-description"> '.$cat->description.' </div> ';
    return $output;
}

谢谢

【问题讨论】:

    标签: woocommerce divi


    【解决方案1】:

    现在可以使用了。对于处于相同情况的其他人,请将此代码添加到您的(子)主题中的 functions.php 文件中。

    add_shortcode('cat_desc', 'cat_desc_shortcode');
    function cat_desc_shortcode() {
        
        global $wp_query;
        $cat = $wp_query->get_queried_object();
        
        if( $cat == null ) return;
    
        $output = nl2br($cat->description);
        return $output;
    }
    

    然后在您的布局中使用短代码 [cat_desc],您希望在其中显示类别描述。这至少对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 2021-10-09
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多