Created
September 14, 2011 20:28
-
-
Save ocean90/1217688 to your computer and use it in GitHub Desktop.
Extend post_class with a class for parent category
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 | |
/** | |
* Erweitert post_class() um eine Klasse für Elternkategorien. | |
* | |
* @author Dominik Schilling | |
* @license GPLv2 | |
* @link http://wpgrafie.de/178/ | |
* | |
* @version 0.2 | |
*/ | |
function ds_add_parent_category_class( $classes ) { | |
$cats = get_the_category(); | |
if ( empty( $cats ) ) | |
return $classes; | |
foreach ( $cats as $cat ) { | |
$parent_cat = get_category( $cat->category_parent ); | |
if ( ! is_wp_error( $parent_cat ) ) | |
$classes[] = 'parent-category-' . sanitize_html_class( $parent_cat->slug, $parent_cat->term_id ); | |
} | |
return $classes; | |
} | |
add_filter( 'post_class', 'ds_add_parent_category_class' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment