wordpress分类描述调用category_description()

技术文档 2024年1月5日

下面是站易WP模板收集的wordpress分类描述调用相关的代码片断

以分类ID调用分类描述

echo category_description(3);

通过分类别名来调用分类描述

echo category_description(get_category_by_slug('my-category')->term_id);

通过分类标题来调用分类描述

<div>
    <strong>
        single_cat_title(__('Currently browsing', 'textdomain'));
    </strong>: 
    echo category_description();
</div>

判断有无分别描述,如果有输出分类描述

if (category_description()) {
    echo '<div>' . category_description() . '</div>';
}

分类描述在循环中的调用方法

if (have_posts()) : 
    while (have_posts()) : the_post();
        echo '<div>' . category_description(get_the_category()[0]->cat_ID) . '</div>';
    endwhile; 
endif;

相关文章