dowbwrr3590709 2011-04-27 09:45
浏览 58
已采纳

根据URL中的变量添加到页面标题标记

I have seen the following thread but it's a bit beyond me...

How can I change the <title> tag dynamically in php based on the URL values

Basically, I have a page index.php (no php in it just named to future proof - maybe now!). It contains numerous lightbox style galleries which can be triggered from an external link by a variable in the URL - e.g. index.php?open=true2, index.php?open=true3, etc.

I would like the index.php title tag - to include existing static data + append additional words based on the URL variable - e.g. if URL open=true2 add "car gallery", if URL open=true3 add "cat gallery", if URL has no variable append nothing to title.

Can anyone assist? I have been searching but either missed the point of posts or it hasn't been covered (to my amateaur level).

Many thanks. Paul.

  • 写回答

5条回答 默认 最新

  • dscbxou1900343 2011-04-27 09:56
    关注

    At the top of your php script put this:

    <?php
    
    # define your titles
    $titles = array('true2' => 'Car Gallery', 'true3' => 'Cat Gallery');
    
    # if the 'open' var is set then get the appropriate title from the $titles array
    # otherwise set to empty string.
    $title = (isset($_GET['open']) ? ' - '.$titles[$_GET['open']] : '');
    
    ?>
    

    And then use this to include your custom title:

    <title>Pauls Great Site<?php echo htmlentities($title); ?></title>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集