Skip to content

Instantly share code, notes, and snippets.

@ideag
Created July 10, 2014 15:21
Show Gist options
  • Select an option

  • Save ideag/b394d6a1fff0671ff7d7 to your computer and use it in GitHub Desktop.

Select an option

Save ideag/b394d6a1fff0671ff7d7 to your computer and use it in GitHub Desktop.
get_template_part() replacement to fix variable scope problem in WordPress
<?php
function klausk_template_part($slug,$name=null) {
do_action( "get_template_part_{$slug}", $slug, $name );
$templates = array();
$name = (string) $name;
if ( '' !== $name )
$templates[] = "{$slug}-{$name}.php";
$templates[] = "{$slug}.php";
return locate_template($templates);
}
?>
<?php
$post_id = 100;
include(klausk_template_part('loop','index' ));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment