May I do this without plugins? Maybe few hacks?
Note: by WordPress standards, ANY category that has been designated a Parent category is not meant to be checked in the category hierarchy when writing posts. Meaning, only the latest generation category should be checked. Think of it like this, only the youngest generation gets the action.
But assuming you are checking both parent and child categories when writing posts you need to check each post’s category to make sure only category 4 is in place. See Template_Tags/get_the_category
Maybe you can explain how to make This filter by category? Thank you!
Not sure what you are asking as that is a page so see the Page of Posts example in the Pages article.
I do not know what I changed in the code, but now the subcategory are displayed along with all other posts from the parent category and the other subcategories. When I click on a subcategory, the page just reloads, and should include only those who belong to this subcategory. Maybe in code something is wrong. I did not notice the error. Codex doesn’t help. Please help to understand.
Portfolio.php
<?php
/*
Template Name: Portfolio
*/
?>
<?php get_header() ?>
<?php
$catid = 4,5,6;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat='.$catid.'&paged='.$paged);
$wp_query->is_archive = true; $wp_query->is_home = false;
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="Content">
the_excerpt();
</div>
<?php endwhile; ?>
<?php else : ?>
<h2 class="post-title"><?php _e('404 - Not Found'); ?></h2>
<p><?php _e('Nothing's found.'); ?></p>
<?php endif; ?>
<?php get_footer() ?>
And code for category portfolio template in functions.php
add_filter( 'category_template', 'my__template' );
function my_template( $template ) {
$catid = 4,5,6;
$catid = strpos( $catid , ',' ) ? explode( ',' , $catid ) : array( (int) $catid );
if( is_category( $catid ) )
$template = locate_template( array( 'portfolio.php') );
else
$template = locate_template( array( 'category.php' ) );
return $template;
}
Whats wrong? Thanks!
Btw no one plugin cant resolve problem.