Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1201629

    Team:

    I would like to automatically display author, date and categories in a box left to the blog content area. I am currently doing this manually (not yet the categories, though)…

    https://snipboard.io/53l0P9.jpg

    … using a simple text box:

    https://snipboard.io/P0ZoYB.jpg

    Is there a way to automatise this, such that the box displays the author, the publication date and the categories without entering such info manually?

    Thanks,
    Magnus

    #1202722

    Hey mbosse99,

    The blog posts meta is shown automatically only on blogposts built with the Classic editor, when you build bosts with the Advanced Layout Builder you need to add it manually.

    But you can have a look at the solution posted here:
    https://kriesi.at/support/topic/post-using-advanced-editor-how-to-insert-post-meta-info-title-date-etc/

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1203924

    Thanks Victoria:

    I figured the following:

    for Post Title:

    function post_title_shortcode(){
    	global $post;
    	return get_the_title($post->ID);
    }
    add_shortcode( 'sc_post_title', 'post_title_shortcode' );

    For Post Date:

    function post_date_shortcode(){
    	global $post;
    	return get_the_date('Y-m-d', $post->ID);
    }
    add_shortcode( 'sc_post_date', 'post_date_shortcode' );

    For Post Category:

    function post_category_shortcode(){
    global $post;
    return get_the_category($post->ID);
    }
    add_shortcode( ‘sc_post_category’, ‘post_category_shortcode’ );

    Now what would I need for Post Author?

    Thanks,
    Magnus

    #1204037

    Hi Magnus,

    You need to use the get_the_author() function.

    Here are the docs for you:

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1205495

    Hi Victoria:

    a bit late but still – success – almost! I now can automatically include post title, date and author into a blog post. What does not work is the category – it always returns ‘Array’ as a display.

    Here is the function I used – what is wrong? Note that I might have more than one category for a single post.

    function post_category_shortcode(){
    global $post;
    return get_the_category($post->ID);
    }
    add_shortcode( 'sc_post_category', 'post_category_shortcode' );

    Thanks!
    Magnus

    • This reply was modified 4 years, 7 months ago by mbosse99.
    #1205813

    Hi Magnus,

    Because posts have many categories and they are returned as an array and so have to be treated differently.

    You can try using this function instead:

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1207475

    Excellent, thanks a lot – that solved it!

    #1207564

    Hi,

    I’m glad this was resolved. If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Blog Posts: Automatically display author, date, and categories?’ is closed to new replies.