-
Author
Tagged: meta, post-meta, custom post
-
December 7, 2014 at 02:55 #37941solokcoParticipant
Is there a way to activate POST META just for CUSTOM POSTS??
I already created the child theme and all the PAGE-PARTS that I’m modifying, but I can’t manage to enable the POST META just for this kind of posts.
I found in the SINGLE file the function kleo_postmeta_enabled() but I don’t know if that’s the correct approach.
Thanks
December 7, 2014 at 12:40 #37965sharmstrModeratorWell, that only sets the css class for the div. The actual meta info is printed out later in one of the content-xxx files.
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
December 7, 2014 at 12:46 #37966sharmstrModeratorIf it were me, I’d only touch it on the single.php page. Then in my functions.php file, I’d do something like the following so you dont have to keep child copies of all the content-xxx files
COPY CODEfunction kleo_entry_meta($echo=true, $att=array()) { if (get_post_type() == 'yourcpt') { $meta_list = array(); // Translators: used between list items, there is a space after the comma. $categories_list = get_the_category_list( __( ', ', 'kleo_framework' ) ); // Translators: used between list items, there is a space after the comma. $tag_list = get_the_tag_list( '', __( ', ', 'kleo_framework' ) ); $date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>', esc_url( get_permalink() ), esc_attr( get_the_time() ), esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ) ); $author = sprintf( '<a href="%1$s" title="%2$s" rel="author">%3$s</a>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'kleo_framework' ), get_the_author() ) ), get_the_author() ); $meta_list[] = '<small class="meta-author">'.$author.'</small>'; $meta_list[] = '<small>'.$date.'</small>'; $cat_tag = array(); if ( $categories_list ) { $cat_tag[] = $categories_list; } if ($tag_list) { $cat_tag[] = $tag_list; } if (!empty($cat_tag)) { $meta_list[] = '<small class="meta-category">'.implode(", ",$cat_tag).'</small>'; } //comments if (!isset($att['comments']) || (isset($att['comments']) && $att['comments'] !== false)) { $meta_list[] = '<small class="meta-comment-count"><a href="'. get_permalink().'#comments">'.get_comments_number().' <i class="icon-chat-1 hover-tip" data-original-title="'.sprintf( _n( 'This article has one comment', 'This article has %1$s comments', get_comments_number(), 'kleo_framework' ),number_format_i18n( get_comments_number() ) ).'" data-toggle="tooltip" data-placement="top"></i></a></small>'; } if ($echo) { echo implode(", ", $meta_list); } else { return implode(", ", $meta_list); } } }
Just change ‘yourcpt’ to whatever your cpt is.
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
December 10, 2014 at 04:02 #38407solokcoParticipantThanks for the Answer. Im trying to implement this as you advice, but should I add any action on the single.php to call this function?
I added the code to my functions and nothing happens, but if I call this function in single.php, it shows up, but I know that’s not the correct way, that’s why I’m asking.
Thanks for your time.
December 10, 2014 at 04:22 #38408sharmstrModeratorHmmm. I’m guessing your cpt doesnt have post types then (audio, image, video, etc).
If it works by adding it to single.php then do it. It shouldn’t hurt any of the other posts since the function will only display it on your cpt. If you run into issues, you can create your own single page by naming is single-yourcptname.php in your child theme, then add the kleo_entry_meta call. Then you’re really keeping your custom files separate. That’s what I do anyways.
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
December 11, 2014 at 14:43 #38572sharmstrModeratorWere you able to get this sorted?
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
January 3, 2015 at 01:25 #40919solokcoParticipantI got it to work with the code you gave me. But I had to do the following changes to make it work:
- delete the IF Statement inside CONTENT-_____.php
- <?php if( kleo_postmeta_enabled() ): ?>
- Delete the IF statement inside SINGLE-_____.php
- if ( kleo_postmeta_enabled() )
Considering that I have the META option OFF for POSTS inside the THEME OPTION and just wanted to show in CUSTOM POSTS and there is no way to turn ON just for CPT.
So I deleted this lines (Doesn’t work if you comment this lines) and it is working fine now.
-
AuthorPosts
The forum ‘KLEO’ is closed to new topics and replies.