Get_template_part inside a folder

I assume you have a file in templates/masterhead-templatename.php, and it works, it is ok. Correct me if I am wrong, you want to locate this file like this masterhead-templatename.php, basically one folder up, but this wordpress function does not work like this. If the file exists in the root’s theme folder, it does not recognize … Read more

add a hook with get_template_part()

OK, so one simple way would be to edit your template, I assume header.php for where you want the menu to appear. Use the template include to load myfile.php get_template_part(‘template-parts/myfile’); Then inside myfile.php: <?php $search .= ‘<li class=”search”><form role=”search” method=”get” id=”searchform” action=”‘.home_url( “https://wordpress.stackexchange.com/” ).'”><input type=”text” value=”search” name=”s” id=”s” /><input type=”submit” id=”searchsubmit” value=”‘. esc_attr__(‘Search’) .'” /></form></li>’; … Read more

get_template_part and template file names

Codex has very decent explanation of get_template_part() logic: Assuming the theme folder is wp-content/themes, that the parent theme is twentyten, and the child theme is twentytenchild, then the following code — <?php get_template_part( ‘loop’, ‘index’ ); ?> will do a PHP require() for the named files in this order: wp-content/themes/twentytenchild/loop-index.php wp-content/themes/twentytenchild/loop.php wp-content/themes/twentyten/loop-index.php wp-content/themes/twentyten/loop.php Basically you … Read more

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