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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!