动态着陆页标题(不是来自关键字)

时间:2016-09-14 16:27:33

标签: javascript php html

我在Google中创建了一组展示广告,这些广告都会转到同一个目标网页。唯一的问题是我需要根据点击的广告显示特定标题。我会使用网址参数来区分广告,但是,我不想将完整的标题文字放在网址参数中,因为标题相当长。

我认为我需要做的是有一个编码参数,例如" /?hl = 2"然后使用它来动态地用"标题替换h1标签中的文本ABC"或者与该参数相关的标题是什么。

最好的方法是通过一系列javascript if语句来做到这一点吗?或者通过某种php数组?

任何建议将不胜感激。不幸的是,我只能找到有关在线关键字插入的资源,而不是自定义标题。

1 个答案:

答案 0 :(得分:0)

我建议创建一个PHP类并调用一个set函数,该函数使用switch语句选择正确的文本。这就是我在下面的内容。

类文件(headerClass.php)

<?php
    class hlText{

        public function gethlText($selectedHl){
            switch ($selectedHl) {
                case 1:
                $returnedValue = "The First Header";
                break;
                case 2:
                $returnedValue = "The Second Header";
                break;
                case 3:
                $returnedValue = "The Third Header";
                break;
                default:
                $returnedValue = "The Default Header";
            }
            return $returnedValue;
        }

    }
?>

PHP文件(whatever.php)

<?php 

include 'headerClass.php';

$getHl = $_GET['hl'];

$getHeader = new hlText();

$theHeader = $getHeader->gethlText($getHl);

?>

 <!DOCTYPE html>
 <html>
 <head>
    <title>Page Title</title>
 </head>
 <body>

    <h1><?php echo $theHeader; ?></h1>

 </body>
 </html>