Tagged: ,

Viewing 23 posts - 1 through 23 (of 23 total)
  • Author
    Posts
  • #458944

    How does one add the post meta info (title, date, comments etc.) in a custom post using the Advanced Editor? I have seen a few topics touch on this but nothing explaining how to do it. Is this possible using a code block?

    #459818

    Hi Lester!

    You can’t put PHP code directly on a code block but you could make use of WordPress Shortcodes to show things like date or title.

    For comments there’s already an element that lets you include those (Content Elements > Comments).

    Best regards,
    Josue

    #465209

    I cannot seem to figure this out. Is there a sample script for a post title shortcode to be placed into an advanced edit post.

    #465222

    Hey!

    Try adding this at the very end of your theme / child theme functions.php file:

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

    Then in your ALB-enabled Post simply drag a Text Block where you want this and use the following shortcodes:

    [sc_post_title]
    [sc_post_date]

    Cheers!
    Josue

    #465406

    Thank you. I will try this.

    #465408

    Worked like a charm. Thank you.

    #465412

    Hey Josue. Any chance on adding the comments, category and poster like how its displayed without using the advanced editor:

    June 5, 2015 / 0 Comments / in Windows 8 / by Poster

    #465666

    Hey!

    Try with this:

    function post_meta_shortcode(){
    	echo "<span class='post-meta-infos'>";
    	$markup = avia_markup_helper(array('context' => 'entry_time','echo'=>false));
    	echo "<time class='date-container minor-meta updated' $markup>".get_the_time(get_option('date_format'))."</time>";
    	echo "<span class='text-sep text-sep-date'>/</span>";
    
    	    if ( get_comments_number() != "0" || comments_open() ){
    
    	    echo "<span class='comment-container minor-meta'>";
    	    comments_popup_link(  "0 ".__('Comments','avia_framework'),
    	                          "1 ".__('Comment' ,'avia_framework'),
    	                          "% ".__('Comments','avia_framework'),'comments-link',
    	                          "".__('Comments Disabled','avia_framework'));
    	    echo "</span>";
    	    echo "<span class='text-sep text-sep-comment'>/</span>";
    	    }
    
    	    $taxonomies  = get_object_taxonomies(get_post_type($the_id));
    	    $cats = '';
    	    $excluded_taxonomies =  apply_filters('avf_exclude_taxonomies', array('post_tag','post_format'), get_post_type($the_id), $the_id);
    
    	    if(!empty($taxonomies))
    	    {
    	        foreach($taxonomies as $taxonomy)
    	        {
    	            if(!in_array($taxonomy, $excluded_taxonomies))
    	            {
    	                $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' ';
    	            }
    	        }
    	    }
    
    	    if(!empty($cats))
    	    {
    	        echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." ";
    	        echo $cats;
    	        echo '</span><span class="text-sep text-sep-cat">/</span>';
    	    }
    
    	    echo '<span class="blog-author minor-meta">'.__('by','avia_framework')." ";
    	    echo '<span class="entry-author-link" '.avia_markup_helper(array('context' => 'author_name','echo'=>false)).'>';
    	    echo '<span class="vcard author"><span class="fn">';
    	    the_author_posts_link();
    	    echo '</span></span>';
    	    echo '</span>';
    	    echo '</span>';
    	echo '</span>';
    }
    add_shortcode( 'sc_post_meta', 'post_meta_shortcode' );

    Regards,
    Josue

    #466125

    Hi Josue,

    The script display exactly what I want (Thank you) but it does not display where I have the short code which is under the Post Title in a text block using the advanced builder. For some reason it is going above all post design blocks etc. You can see what I mean with the attached image link in the Private Content area.

    #466127

    I have added this image of the adv builder layout to give you a better idea. I can give you access to the site but I would need your ip address as I have a coming soon page with ip filters.

    #466158

    Hi!

    Change code to:

    function post_meta_shortcode(){
    	ob_start();
    	echo "<span class='post-meta-infos'>";
    	$markup = avia_markup_helper(array('context' => 'entry_time','echo'=>false));
    	echo "<time class='date-container minor-meta updated' $markup>".get_the_time(get_option('date_format'))."</time>";
    	echo "<span class='text-sep text-sep-date'>/</span>";
    
    	    if ( get_comments_number() != "0" || comments_open() ){
    
    	    echo "<span class='comment-container minor-meta'>";
    	    comments_popup_link(  "0 ".__('Comments','avia_framework'),
    	                          "1 ".__('Comment' ,'avia_framework'),
    	                          "% ".__('Comments','avia_framework'),'comments-link',
    	                          "".__('Comments Disabled','avia_framework'));
    	    echo "</span>";
    	    echo "<span class='text-sep text-sep-comment'>/</span>";
    	    }
    
    	    $taxonomies  = get_object_taxonomies(get_post_type($the_id));
    	    $cats = '';
    	    $excluded_taxonomies =  apply_filters('avf_exclude_taxonomies', array('post_tag','post_format'), get_post_type($the_id), $the_id);
    
    	    if(!empty($taxonomies))
    	    {
    	        foreach($taxonomies as $taxonomy)
    	        {
    	            if(!in_array($taxonomy, $excluded_taxonomies))
    	            {
    	                $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' ';
    	            }
    	        }
    	    }
    
    	    if(!empty($cats))
    	    {
    	        echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." ";
    	        echo $cats;
    	        echo '</span><span class="text-sep text-sep-cat">/</span>';
    	    }
    
    	    echo '<span class="blog-author minor-meta">'.__('by','avia_framework')." ";
    	    echo '<span class="entry-author-link" '.avia_markup_helper(array('context' => 'author_name','echo'=>false)).'>';
    	    echo '<span class="vcard author"><span class="fn">';
    	    the_author_posts_link();
    	    echo '</span></span>';
    	    echo '</span>';
    	    echo '</span>';
    	echo '</span>';
    	return ob_get_clean();
    }
    add_shortcode( 'sc_post_meta', 'post_meta_shortcode' );

    Cheers!
    Josue

    #466160

    You are the man! Thank-You!!

    #466172

    You are welcome, glad to help :)

    Regards,
    Josue

    #748161

    How do you get the category of the post? I have the code currently as

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

    this shortcode is being passed in a link to a gravity form but the resulting display in the dynamically populated field is Array. Only one category is ticked.

    #750352

    Hey!

    Please replace the code with the following:

    function post_category_shortcode(){
    	global $post;
    	$categories = get_the_category($post->ID);
    	$separator = ' ';
    	$output = '';
    	if ( ! empty( $categories ) ) {
    	    foreach( $categories as $category ) {
    	        $output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</a>' . $separator;
    	    }
    
    	}
    	return trim( $output, $separator );
    }
    add_shortcode( 'sc_post_category', 'post_category_shortcode' );

    // https://developer.wordpress.org/reference/functions/get_the_category/

    Best regards,
    Ismael

    #801472

    Can you please give me the shortcode for comments?

    Josue’s code does not work for me, but if i paste all different shortcodes into a textblock it works. I am fine with that.
    What is missing next to

    [sc_post_title]
    [sc_post_date]
    [sc_post_category]

    are the comments.

    Thank you very much! You guys really rock.

    #802615

    Hi Tobiy,

    Please refer to this thread for a possible solution.

    Is that what you need to do?

    Best regards,
    Victoria

    #803004

    Hi Victoria,

    i need this:

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

    for comments. So i can add the shortcode for comments. But i dont want to do mistakes. Thank you.

    #803572

    Hi Tobiy,

    Unfortunately, this kind of customization is out of the scope of our support. You could hire a freelancer to do it for you.

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

    #905092

    Hi –
    Using this thread, I’ve been able to add shortcodes to Enfold to display post title, data and author. I’m wondering if it’s possible to create a shortcode to display the post featured image. I think it involves “get_the_post_thumbnail” but can’t quite figure out the code to display in Avia.

    Thanks in advance for your help
    Jon

    #905766

    Hi,

    Can you please take a look here
    https://wordpress.stackexchange.com/questions/213768/featured-image-shortcode

    and check if it matches your needs

    Best regards,
    Basilis

    #1089244

    Hi, I’m trying to save a post as a template by using Avia Template Editor. The page shows an error message saying there is no element to be saved. How could we solve it?
    I’m using both Lastest version of WP and Enfold template.
    Many thanks for your help.
    David

    #1089792

    Hi,


    @seomar
    : Please open a new ticket or thread and place the site credentials in the private field.

    Best regards,
    Ismael

Viewing 23 posts - 1 through 23 (of 23 total)
  • The topic ‘Post using Advanced Editor. How to insert Post Meta info (Title, Date etc.) ?’ is closed to new replies.