Php标题根据页面链接到不同的链接

时间:2012-06-15 00:52:49

标签: php header

我最近将23个html页面的双语网站更改为23个php页面(该网站是:www.creativemindspcs.org。)通过此更改,我包含了php页眉,页脚和导航。

我无法弄清楚如何根据我所在的页面更改标题链接。

实施例。关于我们的英文页面。在标题中,我有一个说“Espanol”的链接。当你点击该链接时,它会带你到关于我们的西班牙语页面,但现在因为php标题包含在所有页面上,它只链接到一个页面而不是正确的页面。

如何根据需要访问的页面更改这些链接?有人有一个很好的教程吗?

HTML代码:

<header><insert php code here> include('includes/header.php');

包含标题代码:

<!--==============================header=================================-->

<div id="header" class="editable">

    <div class="inner" >

        <div class="meta-info">

        <div class="extra-wrap">

        <ul class="social-links">

        <li><a href="index.html">English</a></li>

        <li><a href="esp-index.html">Espa&#xF1;ol</a></li>

        <li><a href="contactus.html">Contact Us</a></li>
        </ul>



        <form id="main-search" action="search.php"  >

        <input type="text" name="search"  style="background-color:#CCCCCC" >

        <a class="search-submit" onClick="document.getElementById('main-search').submit()" ></a>
        </form>
        </div>


        <br><br><br><a href="supportus.html" class="button3">Donate</a>  <a href="apply.html" class="button4">Apply</a>     </div>

        <img src="site/images/CMLOGO.GIF" align="top" alt="Guitar Logo"><a href="index.html"></a>     

</div>

<div class="clear"></div>

        </div>

3 个答案:

答案 0 :(得分:1)

因此,双语页面的方法通常是以不同语言存储网站不同部分的哈希值,然后提供相同的模板页面。但在你的情况下,看起来你已经使用链接进入了一个不同但相似的方向。我想说看看初学者https://stackoverflow.com/questions/1228018/php-multilingual-site

答案 1 :(得分:1)

您可以使用PHP $ _ SERVER ['variable_name']

在此处检查数组变量:http://br2.php.net/manual/en/reserved.variables.server.php

我可能会使用 $ _ SERVER ['SCRIPT_FILENAME'] $ _ SERVER ['PHP_SELF'] $ _ SERVER ['REQUEST_URI']

您可以在包含的标题中看到可能的结果,以检查变量:

echo "<pre>";
print_r($_SERVER);
echo "</pre>"; 

所以,你的链接可能是这样的:

<a href="<?php $_SERVER['REQUEST_URI']; ?>spanish.html">

答案 2 :(得分:0)

假设您使用的是Apache,我建议您使用mod_rewrite重写您的网址。因此,例如,当用户访问页面esp-content.html时,URL将被重写为content.html?lang=esp。然后只需在所有链接中包含语言代码:

$lang = (isset($_GET['lang'])) ? urlencode($_GET['lang']) . '-' : null;
echo '<a href="'.$lang.'content.html">';