[wp-hackers] front-page.php always overrides home.php?
Chip Bennett
chip at chipbennett.net
Fri Nov 19 19:38:05 UTC 2010
All,
If a Theme defines both a "home.php" template file (for a custom "home" page
displaying Posts) and a "front-page.php" template file (for a custom "home"
page displaying a static Page), it appears that "front-page.php" will always
take precedence over "home.php":
Here's the definition of
is_front_page()<http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/query.php#L353>
:
344 /**
345 * Whether current page query is the front of the site.
346 *
347 * @since 2.5.0
348 * @uses is_home()
349 * @uses get_option()
350 *
351 * @return bool True, if front of site.
352 */
353 function is_front_page() {
354 // most likely case
*355 if ( 'posts' == get_option('show_on_front') && is_home() )*
356 return true;
357 elseif ( 'page' == get_option('show_on_front') &&
get_option('page_on_front') && is_page(get_option('page_on_front')) )
358 return true;
359 else
360 return false;
361 }
And then here's the relevant code from the template
loader<http://core.trac.wordpress.org/browser/trunk/wp-includes/template-loader.php#L21>
:
21 if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
22 $template = false;
23 if ( is_404() && $template = get_404_template()
) :
24 elseif ( is_search() && $template = get_search_template()
) :
25 elseif ( is_tax() && $template =
get_taxonomy_template() ) :
*26 elseif ( is_front_page() && $template =
get_front_page_template() ) :*
*27 elseif ( is_home() && $template = get_home_template()
) :*
28 elseif ( is_attachment() && $template =
get_attachment_template() ) :
29 remove_filter('the_content', 'prepend_attachment');
30 elseif ( is_single() && $template = get_single_template()
) :
31 elseif ( is_page() && $template = get_page_template()
) :
32 elseif ( is_category() && $template =
get_category_template() ) :
33 elseif ( is_tag() && $template = get_tag_template()
) :
34 elseif ( is_author() && $template = get_author_template()
) :
35 elseif ( is_date() && $template = get_date_template()
) :
36 elseif ( is_archive() && $template =
get_archive_template() ) :
37 elseif ( is_comments_popup() && $template =
get_comments_popup_template() ) :
38 elseif ( is_paged() && $template = get_paged_template()
) :
39 else :
40 $template = get_index_template();
41 endif;
42 if ( $template = apply_filters( 'template_include', $template ) )
43 include( $template );
44 return;
45 endif;
Is this the intended behavior? If so, it would seem to make the use of
"home.php" obsolete, since "front-page.php" covers both use cases.
(And sorry for the incredibly belated question. I know that "front-page.php"
has been around for a year. I've just never actually *used* it, so wasn't
aware of how it was defined/used by the template loader.)
Chip
More information about the wp-hackers
mailing list