Changeset 449245
- Timestamp:
- 10/09/2011 08:53:08 PM (14 years ago)
- File:
-
- 1 edited
-
show-theme-file/trunk/showThemeFile.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
show-theme-file/trunk/showThemeFile.php
r394789 r449245 1 1 <?php 2 3 2 /* 4 3 Plugin Name: Show Theme File … … 9 8 */ 10 9 11 function getThemeFile() { 12 global $wp_query; 13 global $post; 10 function getWpTemplate() { 11 if (defined('WP_USE_THEMES') && WP_USE_THEMES) { 12 $template = false; 13 14 if (is_404() && $template = get_404_template()): 15 elseif (is_search() && $template = get_search_template()): 16 elseif (is_tax() && $template = get_taxonomy_template()): 17 elseif (is_front_page() && $template = get_front_page_template()): 18 elseif (is_home() && $template = get_home_template()): 19 elseif (is_attachment() && $template = get_attachment_template()): 20 elseif (is_single() && $template = get_single_template()): 21 elseif (is_page() && $template = get_page_template()): 22 elseif (is_category() && $template = get_category_template()): 23 elseif (is_tag() && $template = get_tag_template()): 24 elseif (is_author() && $template = get_author_template()): 25 elseif (is_date() && $template = get_date_template()): 26 elseif (is_archive() && $template = get_archive_template()): 27 elseif (is_comments_popup() && $template = get_comments_popup_template()): 28 elseif (is_paged() && $template = get_paged_template()): 29 else: 30 $template = get_index_template(); 31 endif; 14 32 15 $themeDir = TEMPLATEPATH; 16 $themeFile = ''; 17 18 if (is_home()) { 19 if (file_exists($themeDir . '/' . 'home.php')) { 20 $themeFile = 'home.php'; 21 } 22 23 return $themeFile; 33 return str_replace(ABSPATH, '', $template); 34 } else { 35 return null; 24 36 } 25 26 if (is_front_page()) {27 if (file_exists($themeDir . '/' . 'front-page.php')) {28 $themeFile = 'front-page.php';29 }30 31 return $themeFile;32 }33 34 if (is_404()) {35 if (file_exists($themeDir . '/' . '404.php')) {36 $themeFile = '404.php';37 }38 39 return $themeFile;40 }41 42 if (is_search()) {43 if (file_exists($themeDir . '/' . 'search.php')) {44 $themeFile = 'search.php';45 }46 47 return $themeFile;48 }49 50 51 if (is_date()) {52 if (file_exists($themeDir . '/' . 'date.php')) {53 $themeFile = 'date.php';54 } elseif (file_exists($themeDir . '/' . 'archive.php')) {55 $themeFile = 'archive.php';56 }57 58 return $themeFile;59 }60 61 if (is_author()) {62 $authorNiceName = $wp_query->queried_object->user_nicename;63 $authorID = $wp_query->queried_object->ID;64 65 if (file_exists($themeDir . '/' . 'author-' . $authorNiceName . '.php')) {66 $themeFile = 'author-' . $authorNiceName . '.php';67 } elseif (file_exists($themeDir . '/' . 'author-' . $authorID . '.php')) {68 $themeFile = 'author-' . $authorID . '.php';69 } elseif (file_exists($themeDir . '/' . 'author.php')) {70 $themeFile = 'author.php';71 } elseif (file_exists($themeDir . '/' . 'archive.php')) {72 $themeFile = 'archive.php';73 }74 75 return $themeFile;76 }77 78 if (is_category()) {79 $theCategory = get_category(get_query_var('cat'));80 81 $theSlug = $theCategory->slug;82 $theID = $theCategory->cat_ID;83 84 if (file_exists($themeDir . '/' . 'category-' . $theSlug . '.php')) {85 $themeFile = 'category-' . $theSlug . '.php';86 } elseif (file_exists($themeDir . '/' . 'category-' . $theID . '.php')) {87 $themeFile = 'category-' . $theID . '.php';88 } elseif (file_exists($themeDir . '/' . 'category.php')) {89 $themeFile = 'category.php';90 } elseif (file_exists($themeDir . '/' . 'archive.php')) {91 $themeFile = 'archive.php';92 }93 94 return $themeFile;95 }96 97 98 if (is_tag()) {99 $tagInfo = get_query_var('tag_id');100 $theTag = get_tag($tagInfo);101 102 $theSlug = $theTag->slug;103 $theID = $theTag->tag_id;104 105 if (file_exists($themeDir . '/' . 'tag-' . $theSlug . '.php')) {106 $themeFile = 'tag-' . $theSlug . '.php';107 } elseif (file_exists($themeDir . '/' . 'tag-' . $theID . '.php')) {108 $themeFile = 'tag-' . $theID . '.php';109 } elseif (file_exists($themeDir . '/' . 'tag.php')) {110 $themeFile = 'tag.php';111 } elseif (file_exists($themeDir . '/' . 'tag.php')) {112 $themeFile = 'archive.php';113 }114 115 return $themeFile;116 }117 118 if (is_archive()) {119 $thePostID = $wp_query->post->ID;120 $thePostType = get_post_type($thePostID);121 122 if (file_exists($themeDir . '/' . 'archive-' . $thePostType . '.php')) {123 $themeFile = 'archive-' . $thePostType . '.php';124 } elseif (file_exists($themeDir . '/' . 'archive.php')) {125 $themeFile = 'archive.php';126 }127 128 return $themeFile;129 }130 131 if (is_single()) {132 $thePostID = $wp_query->post->ID;133 $thePostType = get_post_type($thePostID);134 135 if (file_exists($themeDir . '/' . 'single-' . $thePostType . '.php')) {136 $themeFile = 'single-' . $thePostType . '.php';137 } elseif (file_exists($themeDir . '/' . 'single.php')) {138 $themeFile = 'single.php';139 }140 }141 142 if (is_attachment()) {143 $thePostID = $wp_query->post->ID;144 145 $mimeType = get_post_mime_type($thePostID);146 147 if (file_exists($themeDir . '/' . $mimeType . '.php')) {148 $themeFile = $mimeType . '.php';149 } elseif (file_exists($themeDir . '/' . 'attachment.php')) {150 $themeFile = 'attachment.php';151 } elseif (file_exists($themeDir . '/' . 'single.php')) {152 $themeFile = 'single.php';153 }154 155 return $themeFile;156 }157 158 if (is_page()) {159 $thePost = get_post($post->ID, 'OBJECT');160 $thePostID = $thePost->ID;161 $thePostSlug = $thePost->post_name;162 163 $specificThemeFile = get_post_meta($thePostID, '_wp_page_template', true);164 165 if (($specificThemeFile != 'default') && (file_exists($themeDir . '/' . $specificThemeFile))) {166 $themeFile = $specificThemeFile;167 } elseif (file_exists($themeDir . '/' . 'page-' . $thePostSlug . '.php')) {168 $themeFile = 'page-' . $thePostSlug . '.php';169 } elseif (file_exists($themeDir . '/' . 'page-' . $thePostID . '.php')) {170 $themeFile = 'page-' . $thePostID . '.php';171 } elseif (file_exists($themeDir . '/' . 'page.php')) {172 $themeFile = 'page.php';173 }174 175 return $themeFile;176 }177 178 return false;179 37 } 180 38 181 39 function outputThemeFilename() { 40 global $stfOptions; 41 182 42 echo '<div id="showtheme" style="position: absolute; z-index: 9999; padding: 1em; background: white; color: black; opacity: 0.8; border: dotted 2px #999;">'; 183 echo (get ThemeFile()) ? getThemeFile() : 'Unknown theme file';43 echo (getWpTemplate() !== null) ? getWpTemplate() : 'Unknown theme file'; 184 44 echo '</div>'; 185 45 return; 186 46 } 187 47 188 add_action('wp_head', 'outputThemeFilename'); 48 $stfOptions = array('require_admin' => true); 49 50 if ($stfOptions['require_admin'] == true) { 51 if (current_user_can('administrator')) { 52 add_action('wp_head', 'outputThemeFilename'); 53 } 54 } else { 55 add_action('wp_head', 'outputThemeFilename'); 56 }
Note: See TracChangeset
for help on using the changeset viewer.