dongzaijiao4863 2012-07-21 10:35
浏览 46
已采纳

带有一个头文件的不同页面标题?

How do you do multiple page titles with on header file? Theres one thing though. For the index page, i've got

error_reporting(0);
if ($_GET["error"]=="404") { 
    include("forum/styles/art_air/web_template/overall_header.php");
    include("include/404"); 
    include("include/index");
    include("forum/styles/art_air/web_template/overall_footer.php");
} else { 
    include("forum/styles/art_air/web_template/overall_header.php");
    include("include/index");
    include("forum/styles/art_air/web_template/overall_footer.php");
}

So i would have the header before anything else. So how would i manage to make so that

index?error=404 and index have different titles? Thanks in advance.

  • 写回答

3条回答 默认 最新

  • doubailian4459 2012-07-21 10:38
    关注

    Use JavaScript and document.title.

    Example:

    <script language="javascript">document.title = "My Title"</script>
    

    JS can be used in body.


    Another method is to set a $GLOBAL variable before including everything.

    Example:

    error_reporting(0);
    $GLOBALS['404'] = 0;
    if ($_GET["error"]=="404") { 
        $GLOBALS['404'] = 1;
        include("forum/styles/art_air/web_template/overall_header.php");
        include("include/404"); 
        include("include/index");
        include("forum/styles/art_air/web_template/overall_footer.php");
    } else { 
        $GLOBALS['404'] = 0;
        include("forum/styles/art_air/web_template/overall_header.php");
        include("include/index");
        include("forum/styles/art_air/web_template/overall_footer.php");
    }
    

    In your overall_header.php:

    if($GLOBALS['404'] == 1) echo '<title>404: Not Found</title>';
    else echo '<title>My Title</title>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作