Last active
August 29, 2015 14:08
-
-
Save srikat/4e65fa512eb13eef7742 to your computer and use it in GitHub Desktop.
How to display only the first category that a Post belongs to in Genesis. http://sridharkatakam.com/display-first-category-post-belongs-genesis/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
add_shortcode( 'post_category', 'sk_show_the_first_category_name_only' ); | |
/** | |
* Custom shortcode that returns the first hyperlinked category that entry belongs to | |
* | |
* @author Sridhar Katakam | |
* @link http://codex.wordpress.org/Function_Reference/get_the_category#Show_the_First_Category_Name_Only | |
*/ | |
function sk_show_the_first_category_name_only( $atts ) { | |
$categories = get_the_category( $post->ID ); | |
if( $categories[0] ) { | |
return 'Filed Under: <a href="' . get_category_link( $categories[0]->term_id ) . '">' . $categories[0]->cat_name . '</a>'; | |
} | |
} | |
add_filter( 'genesis_post_meta', 'sk_post_meta_filter' ); | |
/** | |
* Customize entry meta in the entry footer | |
* We are replacing [post_categories] with a custom shortcode, [post_category] | |
* | |
* @author Sridhar Katakam | |
* @link http://sridharkatakam.com/display-first-category-post-belongs-genesis/ | |
*/ | |
function sk_post_meta_filter( $post_meta ) { | |
$post_meta = '[post_category] [post_tags]'; | |
return $post_meta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment