Load all category posts in one template with format ‘posts-of-category-CatSlug’

To load all the category posts in same template file add the below hook to functions.php file :

<?php
function load_cat_parent_template(){
global $post;
$catsArr = array(‘posizioni-aperte’);
$cat = get_the_category($post->ID);
if(in_array($cat[0]->slug,$catsArr)){
$template = TEMPLATEPATH . “/posts-of-category-“.$cat[0]->slug.”.php”;
load_template( dirname( __FILE__ ) . “/child-of-category-“.$cat[0]->slug.”.php” );
exit;
}
}
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s