[Resolved] Category Descriptions Not Displaying

Home Forums Support [Resolved] Category Descriptions Not Displaying

Home Forums Support Category Descriptions Not Displaying

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #612104
    Andy

    Hi,

    I’m using WP Show Posts to display my posts but the Category Descriptions are’nt displaying.

    Any ideas?

    #612494
    Leo
    Staff
    Customer Support

    Hi Andy,

    Are you wanting to show category description within the page header?

    If so take a look at Tom’s solution(s) in this post:
    https://generatepress.com/forums/topic/add-custom_field-description-in-category-header/

    More info on custom fields here:
    https://docs.generatepress.com/article/page-header-template-tags/#custom_field-name

    #612556
    Andy

    No, I want to show them between the page header and the start of the first post. I understand GP shows them by default so wondering why they aren’t for me.

    #612801
    Leo
    Staff
    Customer Support

    That’s because you are using page header which is replacing the normal header with the description.

    If you want to show them between the page header and first post, then you will need to build the shortcode using Tom’s method, then insert them with the generate_before_main_content hook.

    #613523
    Andy

    Ok I tried the following in the ‘Before Content’ field using the GP Hooks Add-on but nothing displayed including my posts.

    <?php if (is_category( '' )) 
    
    add_shortcode( 'term_description', 'tu_term_description' );
    function tu_term_description() {
        ob_start();
        echo term_description( get_queried_object()->term_id', 'category' );
        return ob_get_clean();
    }
    
    <?php endif; ?>

    Any further help appreciated.

    #613578
    Leo
    Staff
    Customer Support

    Add this code:

    add_shortcode( 'term_description', 'tu_term_description' );
    function tu_term_description() {
        ob_start();
        echo term_description( get_queried_object()->term_id, 'category' );
        return ob_get_clean();
    }

    Using one of these methods: https://docs.generatepress.com/article/adding-php/

    Then you can just add this in hooks:

    <?php if ( is_category() ) : ?>
        [term_description]
    <?php endif; ?>
    #613634
    Andy

    Thanks I must have had a brain fart trying to insert the shortcode like I was. When trying to add the shortcode code using the Snippets plugin it’s giving me this error:

    Don’t Panic
    The code snippet you are trying to save produced a fatal error on line 4:

    syntax error, unexpected ”, ” (T_CONSTANT_ENCAPSED_STRING), expecting ‘,’ or ‘)’
    The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

    Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.

    Any ideas?

    #613680
    Leo
    Staff
    Customer Support

    Edited the code above.

    #613798
    Andy

    Thanks Leo it’s working now. Unfortunately it was adding the description before EVERY posted listed in the archive, so I moved the shortcode code to the ‘Inside Content Container’ and it now displays just once before the posts are listed. The only small issue with this is at 768px or below, because it’s not inside an article wrapper it has no left or right padding, so the text runs right to the edge of the pages. I can’t add any CSS and padding to it without it affecting the posts listed below it.

    If you check the URL I provided when I started this thread you will be able see what I mean.

    #613887
    Leo
    Staff
    Customer Support

    Try this instead:

    <?php if ( is_category() ) : ?>
        <div class="cat-description">[term_description]</div>
    <?php endif; ?>

    Then this CSS:

    @media (max-width: 768px) {
        .cat-description {
            margin-left: 20px;
        }
    }
    #614206
    Andy

    Thanks Leo I had already tried something similar but it was adding the margin/padding to the whole page container, however it’s working with your code so not sure what I had done differently.

    Thank you.

    #614478
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

    #646856
    Jai Hari Shankar

    Hello there.I had same issue and came across this forum topic.My description in category page was also not showing.After trying many codes etc i found out that if we don’t have any blogs related to that category it wont show up the description.As soon as i added one blog under that category,description of my category pages started showing.Hope this helps.

    #647083
    Leo
    Staff
    Customer Support

    Thanks for sharing the solution πŸ™‚

    #806926
    Maike

    Hi Leo,

    I’m really trying for find the hooks but I can’t find it.

    I have Generate Pro, dispatch skin (created a child theme) and I watched the video, but I simply don’t know where to add the hooks. πŸ€·πŸΌβ€β™€οΈ

    Can you please help.

    I’m trying to have the category descriptions show.

    Thank you,
    Maike

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