我最近将我的双语网站 23 个 html 页面更改为 23 个 php 页面(该网站是:www.creativemindspcs.org。通过此更改,我包括了 php 页眉、页脚和导航。
我不知道如何根据我所在的页面更改标题链接。
例。英文版"关于我们"页面。在标题中,我有一个链接,上面写着"西班牙语"。当您单击该链接时,它应该会将您带到"关于我们"西班牙语页面,但现在由于所有页面上都包含 php 标头,因此它只链接到一个页面而不是正确的页面。
如何根据需要转到的页面更改这些链接?有人有一个好的教程吗?
网页代码:
<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ñ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>
因此,双语页面的方法通常是以不同的语言存储网站不同部分的哈希值,然后提供相同的模板页面。但是在您的情况下,您似乎利用链接朝着不同但相似的方向前进。我想说看看这里作为初学者 https://stackoverflow.com/questions/1228018/php-multilingual-site
您可以使用 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">
假设你使用的是Apache,我建议使用mod_rewrite
来重写你的URL。因此,例如,当用户访问页面esp-content.html
URL将被重写为content.html?lang=esp
。然后只需在所有链接中包含语言代码:
$lang = (isset($_GET['lang'])) ? urlencode($_GET['lang']) . '-' : null;
echo '<a href="'.$lang.'content.html">';