- This topic has 8 replies, 3 voices, and was last updated 5 years ago by Deep.
-
AuthorPosts
-
April 23, 2019 at 7:40 pm #877109Deep
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.
April 24, 2019 at 4:56 am #877408DavidStaffCustomer SupportHi there,
that user was requiring something more complicated as it was for a Custom Post Type.
Are you wanting to display the normal Posts?April 24, 2019 at 5:35 am #877440DeepHi,
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.
April 24, 2019 at 6:34 am #877495DavidStaffCustomer SupportThe 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:
April 24, 2019 at 6:46 am #877512DeepSee 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.
April 24, 2019 at 7:44 am #877735TomLead DeveloperLead DeveloperNot 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. Update123
to the ID of the category you want to display.April 24, 2019 at 8:05 am #877750DeepYou 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.
April 24, 2019 at 8:07 am #877753TomLead DeveloperLead DeveloperYou’re welcome 🙂
April 24, 2019 at 8:26 am #877776DeepI 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.
-
AuthorPosts
- You must be logged in to reply to this topic.