0

Hi I have a single page ajax website the single page is basically loading all the pages I would like to set the page title depending on the current view.

I have tried using this

<title><!--TITLE--></title>
    <?
$pageContents = ob_get_contents (); // Get all the page's HTML into a string
ob_end_clean (); // Wipe the buffer

// Replace <!--TITLE--> with $pageTitle variable contents, and print the HTML
echo str_replace ('<!--TITLE-->', $pageTitle, $pageContents);
?>

I have then added the titles to the page links like this

  <li class="menu-link">
        <a href="index.php?page=home"><img src="images/menu/home.png" width="72" height="72" alt="Home" />Home</a>
        <?php $pageTitle = 'Saunders-Solutions Freelance Design and Development'; ?>
    </li>
    <li class="menu-link">
        <a href="index.php?page=about"><img src="images/menu/about.png" width="72" height="72" alt="About" />About</a>
        <?php $pageTitle = 'About Saunders-Solutions Freelance Design and Development';  ?>
    </li>

however it always shows the same title for all pages any help appreciated

4

4 回答 4

0

你能打印 HTML 吗?适合我。

print "<TITLE>".$pageTitle."</TITLE>";

然后只需删除设置标题的任何其他代码:

例如:

<title><!--TITLE--></title>
于 2013-04-09T08:09:29.123 回答
0

在 JavaScript 中:

document.title = "New Title";
于 2013-04-09T07:58:18.000 回答
0

变量 $pageTitle 似乎是在用 str_replace 替换后定义的。也许您可以发布更多代码以查看问题所在

于 2013-04-09T07:59:45.393 回答
0
<?
$TITLE[home]="Saunders-Solutions Freelance Design and Development";
$TITLE[about]="About Saunders-Solutions Freelance Design and Development";
?>

<title><?=$TITLE[$_GET[page]]?></title>

<li class="menu-link">
        <a href="index.php?page=home"><img src="images/menu/home.png" width="72" height="72" alt="Home" />Home</a>            
    </li>
    <li class="menu-link">
        <a href="index.php?page=about"><img src="images/menu/about.png" width="72" height="72" alt="About" />About</a>

    </li>
于 2013-04-09T08:25:35.570 回答