-
AuthorPosts
-
June 14, 2015 at 4:22 pm #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?
June 16, 2015 at 5:32 am #459818Hi 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,
JosueJune 27, 2015 at 9:15 am #465209I cannot seem to figure this out. Is there a sample script for a post title shortcode to be placed into an advanced edit post.
June 27, 2015 at 12:26 pm #465222Hey!
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!
JosueJune 28, 2015 at 1:36 am #465406Thank you. I will try this.
June 28, 2015 at 2:04 am #465408Worked like a charm. Thank you.
June 28, 2015 at 3:08 am #465412Hey 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
June 29, 2015 at 9:27 am #465666Hey!
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,
JosueJune 30, 2015 at 3:23 am #466125Hi 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.
June 30, 2015 at 3:34 am #466127I 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.
June 30, 2015 at 4:55 am #466158Hi!
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!
JosueJune 30, 2015 at 4:58 am #466160You are the man! Thank-You!!
June 30, 2015 at 5:26 am #466172You are welcome, glad to help :)
Regards,
JosueFebruary 16, 2017 at 10:50 pm #748161How 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.
- This reply was modified 7 years, 9 months ago by devolsolutions.
February 22, 2017 at 9:47 am #750352Hey!
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,
IsmaelMay 30, 2017 at 12:46 pm #801472Can 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.
June 1, 2017 at 3:51 pm #802615Hi Tobiy,
Please refer to this thread for a possible solution.
Is that what you need to do?
Best regards,
VictoriaJune 2, 2017 at 1:27 pm #803004Hi 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.
June 4, 2017 at 1:08 pm #803572Hi 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,
VictoriaJanuary 30, 2018 at 8:06 pm #905092Hi –
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
JonJanuary 31, 2018 at 8:26 pm #905766Hi,
Can you please take a look here
https://wordpress.stackexchange.com/questions/213768/featured-image-shortcodeand check if it matches your needs
Best regards,
BasilisApril 10, 2019 at 7:54 pm #1089244Hi, 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.
DavidApril 12, 2019 at 12:59 am #1089792 -
AuthorPosts
- The topic ‘Post using Advanced Editor. How to insert Post Meta info (Title, Date etc.) ?’ is closed to new replies.