get_template_part execute with ajax
You don’t need buffer here. get_template_part(‘more’, ‘images’); die();
You don’t need buffer here. get_template_part(‘more’, ‘images’); die();
Why don’t you use a simple function with an argument to achieve that, the code is something like this: function wpse63585_event_list( $fresh = true ) { echo ‘<ul class=”event-items”>’; $yesterday = time() – 24*60*60; $compare = $fresh ? ‘>’ : ‘<‘; $args = array( ‘post_type’ => ‘wr_event’, ‘posts_per_page’ => -1, // show all posts ‘meta_key’ … Read more
First of all note that get_template_part internally uses locate_template, so your feeling that the latter is slower is wrong. If you look at the code, get_template_part is little more than a wrapper for locate_template, so if one work and the other not, there are 2 possibilities: you are using get_template_part wrong there’s some hook on … Read more
You can view the template part by using get_template_part($slug) It’s one of those hidden gems inside of WordPress that don’t get the attention they deserve. The get_template_part function is essentially a PHP include or require, on steroids: It already knows where your theme is located and it will look for the requested file in that … Read more
In category-about.php I have <?php /** * The template for displaying the posts in the About category * */ ?> <!– category-about.php –> <?php get_header(); ?> <?php $args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘about’, ); ?> <?php // important bit set_query_var( ‘query_category’, $args ); get_template_part(‘template-parts/posts’, ‘loop’); ?> <?php get_footer(); ?> and in template … Read more
You can always use the output buffering to store the printing contents in a variable. function return_get_template_part($slug, $name=null) { ob_start(); get_template_part($slug, $name); $content = ob_get_contents(); ob_end_clean(); return $content; } $content = return_get_template_part(‘content’, ‘page’); This would be most preferable to keep using the get_template_part() right now. An alternative would be to use locate_template() function but it … Read more
You can filter the template with the template_include filter. This example will filter the archive template for all archive pages. If you need to do this for a specific archive, use is_post_type_archive( $post_types ) as your condition. Put this in your functions.php file of your child theme. function my_archive_filter( $template) { if ( is_archive() ) … Read more
As of WordPress 3.4, calls to wp_enqueue_script() can be made inline. So, it is perfectly acceptable to call it where needed, such as inside a shortcode callback, or conditionally based upon returned queries, as you’ve done here.
get_template_part() will work the same no matter where or how deep you are within your theme. It always includes relative to the theme (or child theme) root. So if you call the following from anywhere: get_template_part( ‘content’, ‘job-listing’ ); … it will try to load (in order): child-theme/content-job-listing.php parent-theme/content-job-listing.php child-theme/content.php parent-theme/content.php To load parts that … Read more
D’oh, it just needs a global as its inside a function. messages.php: <?php global $message; echo $message; ?>