º¯ÊýÒaÒaÏe½a
´Óµ±Ç°Ö÷Ìaµ÷ÓÃheader.phpÎļþ¡£ÊDz»ÊǺܼoµ¥£¿ºÃ°É£¬Èç¹uÄaÊÇÐÂÊֵĻ°ÕaÀiÒªÌaÐÑһϣ¬ÕaÀiµÄgetºÍget_children()¡¢get_categoryÖеÄgetÂÔÓв»Í¬Ö®´¦¡£
get_headerº¯ÊýÉuÃ÷£¨¶¨Òa£(C)
֮ǰдÎÄÕºÜÉÙ»aдµ½º¯Êý¶¨ÒaµÄ´uÂe£¬ºoÀ´×Ô¼º¿´µÄʱºo¢ÏÖÕa¸oÏ°¹ß²»Ì«ºÃ£¬ËuÒÔ¾o¶¨£¬Ö»ÒªÆªuÔÊÐi£¬¾Í»a°Ñº¯ÊýÖ÷ÌaÌu³oÀ´£¬½±a×Ô¼º*¿´¡£
get_header º¯Êý£¬ÉuÃ÷£¨¶¨Òa£(C)µÄλÖã¬ÊÇÔÚ wp=include/general-template.php ÎļþµÄµÚ 24 ¨C 36 ÐÐ×oÓÒµÄλÖá£
function get_header( $name = null ) {
do_action( 'get_header', $name );
$templates = array();
if ( isset($name) )
$templates[] = "header-{$name}.php";
$templates[] = 'header.php';
// Backward compat code will be removed in a future release
if ('' == locate_template($templates, true))
load_template( ABSPATH . WPINC . '/theme-compat/header.php');
}
get_headerº¯ÊýµÄʹÓÃ
<?php get_header( $name ); ?>
ºÜ¼oµ¥£¬´ÓÉÏÃaeµÄº¯ÊýÉuÃ÷ÖÐÎÒÃÇÒ²ÄÜ¿´³o£¬¸Ãº¯ÊýÖ»½ÓÊÜÒ»¸o±aÁ¿×÷Ϊ²ÎÊý¡£
²ÎÊý½aÊÍ
$name £¬´ÓÉÏÃaeµÄº¯ÊýÉuÃ÷ÖÐÎÒÃÇ¿ÉÒÔ¿´³o£¬$nameÊÇÒ»¸o×Ö*u´®ÐͱaÁ¿£¬ÓÃÀ´µ÷ÓÃheaderµÄ±ðÃuÄ£°a£¬
±ÈÈç $name = ¡°ab¡±£»
Ò²¾ÍÊÇÎÒÃÇÕaÑu
<?php
$name = ¡°ab¡±
get_header( $name );
?>
Õa½«»aµ÷Óà header-ab.php Îļþ×÷ΪÍ*²¿ÎļþµÄµ÷Óá£
Àý×Ó£º
1.¼oµ¥µÄ 404 Ò³Ãae
ÏÂÃaeµÄ´uÂeÊÇÒ»¸o¼oµ¥Ä£°aÎļþ£¬×¨ÃÅÓÃÀ´ÏÔʾ "HTTP 404: Not Found" ´iÎoµÄ £¨Õa¸oÎļþÓ¦¸Ã°uº¬ÔÚÄaµÄÖ÷ÌaÖУ¬ÃuΪ 404.php£(C)
<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
*2.¶aÖÖͲ¿**
Ϊ²»Í¬µÄÒ³ÃaeÏÔʾ²»Í¬µÄÍ*²¿
<?php
if ( is_home() ) :
get_header( 'home' );
elseif ( is_404() ) :
get_header( '404' );
else :
get_header();
endif;
?>
ÕaÐ(C)Ϊ home ºÍ 404 ×¼±¸µÄͲ¿Ó¦¸ÃÖ±ðÃuÃuΪ header-home.php ºÍ header-404.php ¡£