• I have category template portfolio.php for my Portfolio category. This category has child category and when I choose child category I see all my post from child category on custom category template not on portfolio template. How to solve this?
    Before loop I have this code:

    <?php
        $limit = ('10');
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        query_posts('showposts=' . $limit . '&paged=' . $paged .'&cat='4');
        $wp_query->is_archive = true; $wp_query->is_home = false;
    ?>

    I want to see each child category in the same page style like parent category. When I choose child category I want to see only posts from this category not from parent or other child. Use like a filter. Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Deniska

    (@deniska)

    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

    Thread Starter Deniska

    (@deniska)

    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.

    Thread Starter Deniska

    (@deniska)

    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!

    Thread Starter Deniska

    (@deniska)

    Btw no one plugin cant resolve problem.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problem with displaying child categories.’ is closed to new replies.