- This topic has 8 replies, 3 voices, and was last updated 3 years, 11 months ago by
Deep.
-
AuthorPosts
-
April 23, 2019 at 7:40 pm #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.
GeneratePress 2.2.2GP Premium 1.7.8April 24, 2019 at 4:56 am #877408David
StaffCustomer 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?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 24, 2019 at 5:35 am #877440Deep
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.
April 24, 2019 at 6:34 am #877495David
StaffCustomer 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:
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 24, 2019 at 6:46 am #877512Deep
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.
April 24, 2019 at 7:44 am #877735Tom
Lead 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.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 24, 2019 at 8:05 am #877750Deep
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.
April 24, 2019 at 8:07 am #877753Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 24, 2019 at 8:26 am #877776Deep
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.
-
AuthorPosts
- You must be logged in to reply to this topic.