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!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745356353a4624142.html
评论列表(0条)