How to use same theme template for multiple taxonomy terms?

You prepare templates (staying with your example): content-redfruits.php, content-greenfruits.php, content-fruits.php. Then in taxonomy file taxonomy-fruit.php (copy and rename taxonomy.php or index.php), before main loop check the term slug of the currently-queried object. $red_templ = [‘strawberries’, ‘tomatoes’, ‘raspberries’]; // term slugs $green_templ = [‘watermelons’, ‘apples’, ‘kiwi’]; // term slugs $template=”fruits”; $obj = get_queried_object(); if ( $obj … Read more

Different templates for parent and children categories/taxonomies

I suggest creating 3 files 1) regiontemplate-country.php 2) regiontemplate-city.php These 2 will contain the templates for country & city, then 3) taxonomy-region.php In this file, add the code to load the appropriate template <?php $term = get_term_by(‘slug’, get_query_var(‘term’), ‘region’); if((int)$term->parent) get_template_part(‘regiontemplate’, ‘city’); else get_template_part(‘regiontemplate’, ‘country’);

Display Editable Text Above CPT Archive Listings

One of the easiest (although not the only) of ways to achieve this is by creating a custom options panel in the WP dashboard that will allow your client to create and update information that can be used through out your template files with no technical knowledge being necessary. You can either paste the following … Read more

Multiple Single Post templates

As I answered here, since WordPress 4.7 Post-Type-Templates are enabled in the WordPress core. That means that you can create multiple templates for the single post-type view. You create these templates like you would create a normal page template. But you need to add a little more code to these templates: /* Template Name: Funerals … Read more

Different template for subcategories

The template hierarchy has filters for all types of templates. Here we can use category_template, check if the current category has a parent, and load the subcategory.php file in that case: function wpd_subcategory_template( $template ) { $cat = get_queried_object(); if ( isset( $cat ) && $cat->category_parent ) { $template = locate_template( ‘subcategory.php’ ); } return … Read more

Is there a default template file for child pages / subpages?

There is no specifica template for child pages, but you can do this pretty easily with the get_template_part() function. First create a file called “content-child.php”. Second create a file called “content.php”. Next, inside of page.php, place this: if( $post->post_parent !== 0 ) { get_template_part(‘content’, ‘child’); } else { get_template_part(‘content’); } Anything that you want displayed … Read more

Loading partial templates with AJAX/PJAX

If you’re concerned about the performance I would recommend using the WordPress API instead of trying to load markup using ajax. If you look at wp-includes/template-loader.php you can see how WordPress itself figures out which template to use. You could in theory just load that file, but you might have problems with template_redirect. require_once( ABSPATH … Read more