- This topic has 5 replies, 2 voices, and was last updated 1 year ago by
Tom.
-
AuthorPosts
-
December 20, 2019 at 10:02 pm #1110259
Vish
Hi Tom
So, I have been digging around ways to make custom category pages. Figured out that it can be done with WP Show Posts (I have the Pro version too).
I came across this help doc: Use Static Pages as Category Archives
Now, If I follow the above method, I would have to make static category pages for all my categories. The problem is I have too many categories and it does not seem feasible. I want the above method to work for only one category. Is there a way to do it by hardcoding the category name or something?
December 21, 2019 at 10:50 am #1110735Tom
Lead DeveloperLead DeveloperHi there,
Try this:
add_filter('request', function( array $query_vars ) { if ( is_admin() ) { return $query_vars; } if ( isset( $query_vars['category_name'] ) ) { $pagename = $query_vars['category_name']; if ( get_page_by_title( $pagename ) ) { $query_vars = array( 'pagename' => "$pagename" ); } } return $query_vars; } );
It will only work if the page actually exists.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 21, 2019 at 11:16 pm #1110980Vish
Tom
It’s not working. Maybe I am doing something wrong? Here’s what I did:
This is my category URL:
https://randomdomain.com/category/generatepress-themes
I have created a page with WP Show Posts shortcode. This is the URL:https://randomdomain.com/generatepress-themes
I tweaked your code to add the category name like below and added it as a snippet using Code Snippets.
add_filter('request', function( array $query_vars ) { if ( is_admin() ) { return $query_vars; } if ( isset( $query_vars['generatepress-themes'] ) ) { $pagename = $query_vars['generatepress-themes']; if ( get_page_by_title( $pagename ) ) { $query_vars = array( 'pagename' => "$pagename" ); } } return $query_vars; } );
The only change I made is replacing the
category_name
withgeneratepress-themes
December 22, 2019 at 10:00 am #1111395Tom
Lead DeveloperLead DeveloperMy code is actually complete – no need to change it at all π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJanuary 5, 2020 at 12:52 pm #1122941Vish
My bad! I used your code as-is without any changes and it still didn’t work.
Here’s some more information:
My Category Page URL:https://www.example.com/category/wordpress-themes
My Normal Page URL:https://www.example.com/wordpress-themes
I simply copy/pasted your code to code snippets and set it to run everywhere.
Kindly let me know if I am doing something wrong. π
January 5, 2020 at 5:48 pm #1123099Tom
Lead DeveloperLead DeveloperStrange, just to confirm, does this code work for you?: https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/
I know it’s meant for all categories, but I just want to make sure the filter is executing.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.