-
AuthorPosts
-
May 3, 2020 at 11:07 pm #1209351
hello, i was reading an old thread about adding post meta using the layout builder, but seem like some thing is outdated.
can you please explain on how to add post meta (either using shortcodes or as default for all entries)
example
May 2, 2020/ in Uncategorized / by xxxx
tags: xxxxMay 9, 2020 at 10:04 pm #1211511Hey Tarek,
Sorry for the late reply, this shortcode solution still works, it gives you the title and date as two different shortcodes.
For a more complete meta shortcode try adding this code to the end of your functions.php file in Appearance > Editor: (code updated with following fix)function post_meta_shortcode(){ ob_start(); $the_id = avia_get_the_id(); $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>'; } echo "<span class='post-meta-infos' style='margin-top: -25px;'>"; $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>"; } 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' );
and then use the shortcode
[sc_post_meta]
Best regards,
Mike- This reply was modified 4 years, 6 months ago by Mike. Reason: updated code with following fix
May 10, 2020 at 1:35 pm #1211640i am getting the below error. please note that am working with the child theme.
Notice: Undefined variable: the_id in /home2/monomedia/public_html/wp-content/themes/enfold-child/functions.php on line 10
Notice: Undefined variable: the_id in /home2/monomedia/public_html/wp-content/themes/enfold-child/functions.php on line 12
Notice: Undefined variable: the_id in /home2/monomedia/public_html/wp-content/themes/enfold-child/functions.php on line 12
Notice: Undefined variable: the_id in /home2/monomedia/public_html/wp-content/themes/enfold-child/functions.php on line 20
May 10, 2020 at 1:38 pm #1211641Line 10 – $taxonomies = get_object_taxonomies(get_post_type($the_id));
Line 12 – $excluded_taxonomies = apply_filters(‘avf_exclude_taxonomies’, array(‘post_tag’,’post_format’), get_post_type($the_id), $the_id);
Line 20 – $cats .= get_the_term_list($the_id, $taxonomy, ”, ‘, ‘,”).’ ‘;May 10, 2020 at 4:19 pm #1211652Hi,
Thanks for the feedback, perhaps when you copied and pasted the code above you had an error, please include an admin login & FTP access in the Private Content area so we can take a look.
I tested the code in my child theme before I posted it, so it should work.Best regards,
MikeMay 11, 2020 at 2:18 pm #1211840i added a user login in the private area, ftp is disabled for security purposes at the moment, but you can still edit the functions file from the theme editor on wordpress.
May 13, 2020 at 12:15 pm #1212577Hi,
Thanks for the login, I added this to the beginning of the shortcode$the_id = avia_get_the_id();
and now the “notice” is gone, please clear your browser cache and check.Best regards,
MikeMay 13, 2020 at 1:56 pm #1212615Thank you, looks good.
May 14, 2020 at 11:08 am #1212900Hi,
Glad we were able to help, we will close this now. Thank you for using Enfold.For your information, you can take a look at Enfold documentation here
For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)Best regards,
Mike -
AuthorPosts
- The topic ‘Adding post meta using advanced layout building’ is closed to new replies.