[Resolved] Adding Category Description to Custom post type archive

Home Forums Support [Resolved] Adding Category Description to Custom post type archive

Home Forums Support Adding Category Description to Custom post type archive

  • This topic has 7 replies, 2 voices, and was last updated 3 years ago by Tom.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1264492
    David

    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

    #1265146
    Tom
    Lead Developer
    Lead Developer

    Adding it to the content.php file will loop it (as you’ve found out).

    Maybe the_term_description() would work better?

    #1265284
    David

    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

    #1265566
    Tom
    Lead Developer
    Lead Developer

    Glad you got it working πŸ™‚

    #1737219
    Tony

    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

    #1738174
    Tom
    Lead Developer
    Lead Developer

    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>' );
        }
    } );
    #1739914
    Tony

    That helped, thanks! I wrote you a 5* feedback in the WP plugins directory. You deserve it πŸ™‚

    #1740458
    Tom
    Lead Developer
    Lead Developer

    Thank you! Really appreciate it πŸ™‚

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.