Display only parent category in entry meta
-
Hello,
I am trying to play around with the post entry meta to try and display just the parent cateogry of a post. I am using the following which I place in my child theme functions.
if ( ! function_exists( 'twentytwelve_entry_meta' ) ) : /** * Prints HTML with meta information for current post: categories, tags, permalink, author, and date. * * Create your own twentytwelve_entry_meta() to override in a child theme. * * @since Twenty Twelve 1.0 */ function twentytwelve_entry_meta() { // Translators: used between list items, there is a space after the comma. $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) ); // Translators: used between list items, there is a space after the comma. $tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) ); $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( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ), get_the_author() ); // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name. if ( $tag_list ) { $utility_text = __( '%1$s by %3$s<span class="by-author"> %4$s</span>.', 'twentytwelve' ); } elseif ( $categories_list ) { $utility_text = __( 'Posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' ); } else { $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' ); } printf( $utility_text, $categories_list, $tag_list, $date, $author ); } endif;This displays:
|Category by James on date and time|
However every post is placed in a parent category and a child/number of its child categories:
|Web Design WordPress CMS by James on date and time|
How can I ONLY display the parent category a post is tagged in??
Thank you
James
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
The topic ‘Display only parent category in entry meta’ is closed to new replies.