Using get_template_part to retrieve a template file based on current post type

There is built in support for that, kind of. While I don’t see anything wrong with your code, try naming your files on the form archive-mytype.php, content-mytype.php etc. and then call get_template_part like this: <!– This will result in including parts/content-mytype.php –> <?php get_template_part(‘parts/content’, get_post_type( $post )); ?> <p id=”t3-splash-title”><?php $post_type = get_post_type_object( get_post_type($post) ); … Read more

Valid HTML in Template Part

Of course there is. Just do it like this: $sticky = get_option( ‘sticky_posts’ ); $args = array( ‘post_type’ => ‘mission’, ‘ignore_sticky_posts’ => 1, ‘orderby’ => ‘date’, ‘post__not_in’ => $sticky, ‘posts_per_page’ => $count ); $latest_missions = new WP_Query( $args ); if ( $latest_missions->have_posts() ) { echo ‘<ul>’; // prints opening ul tag before list items while … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)