Archived topic
Adding Category Description to Custom post type archive
7 replies · Started by David on May 1, 2020
Hello
I've added a custom post type called projects and also a taxonomy for the categories called projects-category
I've then set up...
single-projects.php
archive-projects.php
content-projects.php
taxonomy-projects-category.php
And set the archive-projects.php and taxonomy-projects-category.php to call in the contents-projects.php now if I try and show the category description below the title header on the category pages it doesn't show up.
http://185.20.51.60/~bentleysbuilders/projects-category/extensions-renovations/
If I add this to the archive-projects.php page nothing shows...
<?php
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
If I add it to the content-projects.php file it shows the description twice...
<?php
/**
* The template for displaying posts within the loop.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
?>
<?php
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
<div class="grid-50 tablet-grid-50 mobile-grid-100">
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><div class="projects-archive-outer">
<div class="project-archive-title">
<!-- POST TITLE -->
<h2><?php the_title(); ?></h2>
</div>
<div class="projects-archive-inner" style="background: linear-gradient(0deg, rgba(0, 0, 0, 0.55) 10%, rgba(96, 97, 97, 0) 100%), url('<?php echo $backgroundImg[0]; ?>') no-repeat; background-position: center;background-size: cover;">
</div></div></a>
</div>
How do I get it to only show up once?
Thanks
Dave
Adding it to the content.php file will loop it (as you've found out).
Maybe the_term_description() would work better?
Hi Tom
This worked...
<?php
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
Just needed to add it to taxonomy-projects-category.php not the archive-projects.php for it to appear on that page.
Thanks for your help though.
Dave
Glad you got it working :)
Hi,
I have archive-video.php and I'm using
the_archive_description( '<div class="taxonomy-description">', '</div>' );.
The description shows, but it shows outside of
<header class="page-header">
</header>
How can I show it inside of that element?
Thank you
You would use this hook: generate_after_archive_title
So:
add_action( 'generate_after_archive_title', function() {
if ( is_post_type_archive( 'video' ) ) {
the_archive_description( '<div class="taxonomy-description">', '</div>' );
}
} );
That helped, thanks! I wrote you a 5* feedback in the WP plugins directory. You deserve it :)
Thank you! Really appreciate it :)