Kreativ Font - Kreativ Sound - Kreativ Theme

Codex: Get WordPress posts from a category

Here’s a simple way to extract from your WordPress blog only the post found in certain category to present them on the sidebar.

global $post;
if ( is_category() ) {
$current_category_object = get_category( get_query_var( 'cat' ) );
} else if ( is_single() ) {
$post_categories = wp_get_post_categories( $post->ID );
$current_category_object = get_category( $post_categories[0] );
}
get_sidebar( $current_category_object->slug );

Code snippet by Christopher Ross

Leave a comment

or Subscribe to this comment feed via RSS