Let page load archive outside folder
-
I think I’m missing something.
- I have my theme in wp-content/themes/mytheme
- I made a custom post type (services) in a subfolder: themes/mytheme/services/, wich also has the archive-services.php and style.css
- The archive page load succesfully for the CPT
- But let’s say I also have a page called: Our Services, with the permalink being our-services, I don’t want to also make a page-services.php with a template name to load it, ’cause that would bypass my purpose of all files being loaded from ONE folder.
-
So how do can I make sure the page “Our Services” loads the archive page in the subfolder?
A little more info, I use the template redirect like this:
add_filter( "archive_template", "include_services_template_function" ); add_filter( "single_template", "include_services_template_function" ); function include_services_template_function( $template_path ) { if ( get_post_type() == 'services' ) { if ( is_single() ) { $template_path = dirname( __FILE__ ) . '/single-services.php'; } if ( is_archive() ) { $template_path = dirname( __FILE__ ) . '/archive-services.php'; } } return $template_path; }
But if ( is_page() ) {
obviously doesn’t work.One idea is to make the page-services.php in the subfolder, but in the admin, where I can select a page template in the dropdown, it doesn’t show up.
- The topic ‘Let page load archive outside folder’ is closed to new replies.