Created
July 10, 2014 15:21
-
-
Save ideag/b394d6a1fff0671ff7d7 to your computer and use it in GitHub Desktop.
get_template_part() replacement to fix variable scope problem in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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