Ïê½âWordPress¿ª·¢ÖÐget_header()»ñÈ¡Í·²¿º¯ÊýµÄÓ÷¨

5年以前  |  阅读数:177 次  |  编程语言:PHP 

º¯ÊýÒ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 ¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
Java生成UUID
PHP自定义函数获取搜索引擎来源关键字的方法
年的日历图
发送邮件
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
指定应用ID以获取对应的应用名称
再谈PHP中单双引号的区别详解
Yii2汉字转拼音类的实例代码
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例