• Resolved kicia

    (@kicia)


    Hi,

    I have a blog on my website, it consists of a few categories. I’d like one of the categories to be excluded to another page. I want to have posts from this category displayed in a separate place (and only there).

    I tried with writing such a line to the theme file:

    <?php query_posts( 'cat=ID' ); ?>

    Wrote it in page.php (this file is responsible for the page I’d like to have category posts on) right after this line

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    and yes, I see posts from this category, but they are oddly looped dozens of times, one inside another.
    I have now two posts in this category and for this moment there is only newer of them displayed and looped inside itself.

    Could anyone please tell me how to do it correctly?

Viewing 3 replies - 16 through 18 (of 18 total)
  • Thread Starter kicia

    (@kicia)

    ok, it works totally perfect now

    function exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '11' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    category ’11’ is excluded from the latest posts and from the archive view, but in posts of page they are all as I wanted them to be.

    alchymyth, you helped me very, very much.
    really big thanks to you.

    Thread Starter kicia

    (@kicia)

    I also solved the posts of page thing.
    I have limited the number of posts on the list to 4 using this:

    function hwl_home_pagesize( $query ) {
        if ( is_admin() || ! $query->is_main_query() )
            return;
    
        if ( is_home() ) {
            $query->set( 'posts_per_page', 12 );
            return;
        }
    
        if ( is_post_type_archive( 'testy' ) ) {
            $query->set( 'posts_per_page', 4 );
            return;
        }
    }
    add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );
Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Exclude one of the blog categories to another page’ is closed to new replies.