• hi ,

    i am using the below code on my home page to display recent posts of a particular category ..wht i want to ask is i dont want to show sub category posts in it .

    <ul id="rightSidebarGallery">
    	<?php $photoGal = new WP_Query();$photoGal->query('cat=1&showposts=6'); ?>
    	<?php while ($photoGal->have_posts()) : $photoGal->the_post(); ?>
    	<li><a href="<?php the_permalink() ?>"><img src="<?php viva('NpAdvMainPGThumb','8'); ?>" alt="<?php the_title(); ?>" /></a><p><p><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    	<?php endwhile; wp_reset_query(); ?>
    </ul>

    u can see it live on my blog page at

    https://karomasti.com/telugu-cinema/

    where at right u can find latest songs ..there i want to exclude sub category posts…

    thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try using category__not_in?

    I also noticed that in one of the examples from the Codex page below:

    query_posts(array('category__in' => array(2,6)));

    it says:

    note this does not show posts from any children of these categories

    which might be useful…

    https://codex.www.ads-software.com/Template_Tags/query_posts#Category_Parameters

    Thread Starter sribharath

    (@sribharath)

    for god sake can u put down the code for me here pls…

    my req cat id is 1 and i dont want to show child posts with it

    dnt mind

    i am not able to understand that as i amnew to this

    Go to the page I gave above. It provides simple code examples.

    Hi esmi! Please help me understand why category__in and category__not_in doesnt exclude my child category from loop. I’m try to use this code.

    <?php
        $limit = 6;
        query_posts(array('category__in' =>array(5),'posts_per_page'=>$limit));
        if (have_posts()) : while (have_posts()) : the_post();
        ?>
    
        <!---stuff here-->
    
        <?php endwhile; ?>
        <?php endif; ?>

    Thank you!

    ooopps. All working is fine with category__not_in but some posts that not in category 5 exclude too. I dont understand why?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘removing sub category posts from category on home page’ is closed to new replies.