[Resolved] Display category meta next to date

Home Forums Support [Resolved] Display category meta next to date

Home Forums Support Display category meta next to date

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #756260
    Emma

    Hi, I would like to know how to display the category meta next to the date on my blog posts (exactly like it is on the blog page of your Aspire template). I can’t find any setting anywhere to display it like this. I can see in previous support topics that there is code you can add to move the category meta below the title, but I can’t see any way to display it next to the date like this. Is there a simple setting to do this or does it require coding?

    #756796
    Tom
    Lead Developer
    Lead Developer

    Hi Emma,

    Give this function a shot:

    add_filter( 'generate_post_date_output', function( $date ) {
        echo $date;
    
        $categories_list = get_the_category_list( ', ' );
    
        if ( $categories_list ) {
            echo '<span class="categories">' . $categories_list . '</span>';
        }
    } );

    Then you can add some space around it like this:

    .entry-meta .categories {
        padding: 0 10px;
    }

    Let me know if that helps or not πŸ™‚

    #756881
    Emma

    Thank you, it’s almost perfect, it’s just missing the line between the date and the category. Also, I only want this on the posts on the blog page and not the single post. (exactly how it is on the Aspire template). Thanks πŸ™‚

    #757050
    Tom
    Lead Developer
    Lead Developer

    Try changing your function to this:

    add_filter( 'generate_post_date_output', function( $date ) {
        if ( is_singular() ) {
            return $date;
        }
    
        echo $date;
    
        $categories_list = get_the_category_list( ', ' );
    
        if ( $categories_list ) {
            echo ' | <span class="categories">' . $categories_list . '</span>';
        }
    } );

    Let me know πŸ™‚

    #759953
    Emma

    That’s sorted it, thanks!

    #760297
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad I could help πŸ™‚

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