get_template_part for each level of taxonomy term

Creating and including a template for your custom post type archive is easy, you just need to create a archive-{$post_type}.php template, WordPress will automatically use that template whenever you visit that particular post type’s archive page. Just remember to set the has_archive parameter when registering your post type. As for the taxonomy archive page, you … Read more

Is there any way to get all the name or slug of template parts used in a page?

You could filter the include paths returned by get_included_files by removing any files from the list that are not in your theme (and/or child theme) directory: function get_theme_includes() { $includedfiles = get_included_files(); // normalize theme paths for matching $styledir = str_replace(“\\”,”https://wordpress.stackexchange.com/”,get_stylesheet_directory()); $templatedir = str_replace(“\\”,”https://wordpress.stackexchange.com/”,get_template_directory()); $i = 0; // loop included files foreach ($includedfiles as $includedfile) … Read more

Template part inside shortcode, unexpected reult

The get_template_part() function doesn’t assume any directory name, you have to explicitly supply it. It’s also relative to the active theme directory. So in many of your examples it was looking for the template in the root of your active theme. The correct format would be: get_template_part( ‘template-parts/test-one’ ); If you wanted to, you could … Read more

Filter get_template_part() $args array

There’s no such filter, so what you’re doing is about the best you can do. However, you can optimise a bit by creating functions that wrap the template functions while applying your filter: add_filter( ‘filter_template_part_args’, function( $args, $slug, $name = null ) { $args = wp_parse_args( $args, [ ‘id’ => esc_attr( basename( $slug ) ), … Read more

Some doubts about how to show posts in a custom theme?

get_template_part() is including a template file from the active theme directory. For example: get_template_part(‘content’) will include the template content.php from the theme folder. When having two parameters, it will search for a template named firstParameter-secondParameter.php. So: get_template_part( ‘content’, get_post_format() ); will include the content-{$post_format}.php file. get_post_format() returns one of this defined formats: aside chat gallery … Read more