[Support request] How to display post category archive as home page

Home Forums Support [Support request] How to display post category archive as home page

Home Forums Support How to display post category archive as home page

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #877109
    Deep

    Hi,

    I have a query on how to make a post category archive display as homepage? I don’t like to use any plugin in this regard.

    I found one support ticket in this regard https://generatepress.com/forums/topic/custom-post-type-category-archive-as-a-homepage/
    but seems to quite confusing on my part.

    Please help.

    Thanks.

    #877408
    David
    Staff
    Customer Support

    Hi there,

    that user was requiring something more complicated as it was for a Custom Post Type.
    Are you wanting to display the normal Posts?

    #877440
    Deep

    Hi,
    I simply want a specific category post archive to be displayed in the home page (instead of all categories of posts). Like I want to display only ‘News’ category articles on the homepage.

    Got it. Thanks.

    #877495
    David
    Staff
    Customer Support

    The simplest way would to be to use a Plugin. WP Show Posts is perfect for adding post grids to a static page which means you can add other content to the page. It’s one of Tom’s plugins so is super lightweight:

    https://wpshowposts.com

    #877512
    Deep

    See I told you earlier that I would not use any plugin for this. They will be putting some extra burden on my resources. And I found Mr. Tom was guiding with the code for the same.

    So, I would appreciate if you can help me out of the situation through PHP codes.

    Thanks.

    #877735
    Tom
    Lead Developer
    Lead Developer

    Not sure if it will work, but you could try this:

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

    You’d just need to:

    1. Set your front page to display posts.
    2. Update 123 to the ID of the category you want to display.

    #877750
    Deep

    You are superb. your code was working nice. I am quite impressed with your support.

    But, I simply made a small change in your code to offset the latest post

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

    The problem is I could offset the latest post from the page but when I go down and click load more button, it loads the same set of posts once again. What to do? Thanks.

    #877753
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

    #877776
    Deep

    I am opening this ticket as I have mentioned in my earlier post #877750 that I have a little problem with offset and pagination. Please have a look.

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