最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - How Can I Display the Category Description in a Theme with no Category.php or Archive.php?

programmeradmin3浏览0评论

I'm trying to display the category description on category pages below the title (category name). The challenge is that my theme is based on _s and doesn't have category.php or archive.php files because they're created dynamically. In my child theme, I've found the locations of the content, but inserting an echo of the category description doesn't work.

<h2 class="entry-title">
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>">
         <?php the_title();?>
    </a>
</h2><!-- .entry-title -->
<div class="page-description"> 
    <?php echo category_description( 413 );?>
</div>

I tried making a function to call the description and inserting that instead, but no luck.

The only thing that has successfully called the description anywhere on my site is a shortcode, but I can't get that to work on a category archive page because I can't make it work in the backend.

add_shortcode('cat_desc', 'cat_desc_shortcode');
function cat_desc_shortcode( $atts, $content = null ) {
    $a = shortcode_atts( array(
        'id' => null,
        'slug' => null,
    ), $atts );

    if( $a['id'] ) {
        $cat = get_category( $a['id'] );
    } elseif( $a['slug'] ) {
        $cat = get_category_by_slug( $a['slug'] );
    } else {
        $cat = get_the_category()[0];
    }

    if( $cat == null ) return;

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

    return $output;
}

I really only need to be able to show one specific description for one specific category page. Any help would be appreciated. Thanks!

发布评论

评论列表(0)

  1. 暂无评论