- This topic has 9 replies, 2 voices, and was last updated 3 years ago by David.
-
AuthorPosts
-
April 6, 2021 at 8:36 am #1723662George
I am using this coode to set static pages as category archives:
//Use Static Pages as Category Archives add_filter('request', function( array $query_vars ) { if ( is_admin() ) { return $query_vars; } if ( isset( $query_vars['category_name'] ) ) { $pagename = $query_vars['category_name']; $query_vars = array( 'pagename' => "$pagename" ); } return $query_vars; } );
The template is not being displayed on the static category page, though. It just displays static content. When I deactivate the code, the template is displayed normally. Is there a way around it?
April 7, 2021 at 3:25 am #1724461DavidStaffCustomer SupportHi there,
what is the Content Template being used for ? Is it to display the archive loop ?
April 7, 2021 at 9:08 am #1725114GeorgeYes.
April 8, 2021 at 2:43 am #1725896DavidStaffCustomer SupportThe templates only have a single loop to display
the_content
. So it’s either an archive loop or its a page content loop…. not both.Aside of writing your own custom templates, the alternative would be to hook in the Page content that would need to be pulled in from a custom post type / custom fields.
April 8, 2021 at 2:57 am #1725917GeorgeBut I’ve set my category pages to be static pages so, in theory, it should work, no? Can I at least exclude a certain category from the code provided in the first post?
April 8, 2021 at 5:00 am #1726048DavidStaffCustomer SupportNope – that code is changing the category archive request to a static page – the archive template which has the_loop for displaying the archives is not being loaded.
To exclude a category from static pages – you could change the first condition ie.
if ( is_admin() ) {
to include a
is_category
template tag eg.if ( is_admin() || is_category('your-category-slug') ) {
April 8, 2021 at 5:35 am #1726085GeorgeHmmm. I tried your suggestion but I am getting a 404 error on the selected category. I’ve also deleted the original Travel static category page and resaved my permalinks.
add_filter('request', function( array $query_vars ) { if ( is_admin() || is_category('travel') ) { return $query_vars; } if ( isset( $query_vars['category_name'] ) ) { $pagename = $query_vars['category_name']; $query_vars = array( 'pagename' => "$pagename" ); } return $query_vars; } );
April 8, 2021 at 6:19 am #1726144DavidStaffCustomer SupportHmmm… not sure on this – you could try removing that condition and add a secondary condition to the $query_var addition:
e.gif ( isset( $query_vars['category_name'] ) ) { $pagename = $query_vars['category_name']; if ( $pagename != 'your-category-slug') { $query_vars = array( 'pagename' => "$pagename" ); } }
April 8, 2021 at 6:55 am #1726427GeorgePerfect, that did the trick!
Thanks, David.
April 8, 2021 at 7:09 am #1726444DavidStaffCustomer SupportGreat – glad to hear that!!
-
AuthorPosts
- You must be logged in to reply to this topic.