Site logo

[Resolved] Separate blog and news pages

Home Forums Support [Resolved] Separate blog and news pages

Home Forums Support Separate blog and news pages

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2304062
    Andy

    Hi, I’d like to have both a blog page and a news page on my site. I have the blog page set up to show posts and have created a separate page for news. On the news page, I’ve added a query loop and created a parameter to show just the ‘news’ category, but all the other categories are still appearing. I’d also like to remove the ‘news’ category from the blog page, so tried adding the code suggested here https://generatepress.com/forums/topic/excluding-category-on-blog-site/ but that removes the news category from the news page as well as the blog page. Any help you can provide to get this sorted would really be appreciated, thanks.

    #2304128
    David
    Staff
    Customer Support

    Hi there,

    just out of interest – i assume you know theres a automatic Category Page for your News category ?

    https://www.your-domain.net/category/news/

    Would that be a better solution then the static page and the query loop ?
    The Block Element – Content Template used on your Blog can be applied to the Category Archives too.
    Then the snippet you used should work.

    If not and you need a static page and query loop then try this:

    add_action('pre_get_posts', 'exclude_category_posts');
    function exclude_category_posts( $query ) {
        if( $query->is_main_query() && !is_admin() && !is_singular() ) {
            $query->set('cat', array( -22, -33 ));
        }
    }
    #2304159
    Andy

    Hi David, I was aware of that, although admittedly I had forgotten in my haste to try out the new query loop. You’re right the automatic category is a better solution in this instance, so thank you for the reminder 😆

    It’s useful to know that there is an option to use a static page and the query loop though, so thanks.

    #2304177
    David
    Staff
    Customer Support

    You’re welcome !

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.