是否可以创建链接到php
中多个目录和文件的导航,我不想在更改任何一个链接时更新每个页面上的链接
这些是我的网页:
1) index.php
2) example.php
3) example2.php
4) example/index.php
5) example2/index.php
我希望所有上述文件都有单一导航功能。 (有可能吗?)
// --------编辑----------
我不想用“/”开始链接。它看起来有点不专业。
答案 0 :(得分:0)
这很简单,您只需要创建一个包含在每个页面中的文件。
创建文件navigation.php
<ul class="nav">
<li><a href="index.php">Home</a>
<li><a href="example.php">example</a>
<li><a href="example2php">example2</a>
<li><a href="example3.php">example3</a>
<li><a href="example4.php">example4</a>
</ul>
new将您的导航文件包含在每个页面中。
index.php中的
include "navigation.php";
答案 1 :(得分:0)
如果您不想使用绝对路径(使用&#34; /&#34;),则需要使用&#34; ../"寻找路径。尝试:
<?php //------------ nav.php ------------
$slashcount = substr_count($_SERVER['REQUEST_URI'], '/'); // count '/' in
$dir = str_repeat('../', $slashcount -1); // maybe needs to subtract with 2
?>
<ul class="nav">
<li><a href="<?php echo $dir; ?>index.php">Home</a></li>
<li><a href="<?php echo $dir; ?>example.php">example</a></li>
<li><a href="<?php echo $dir; ?>example2php">example2</a></li>
<li><a href="<?php echo $dir; ?>example/index.php">example3</a></li>
<li><a href="<?php echo $dir; ?>example2/index.php">example4</a></li>
</ul>
调用index.php。
包括&#34; nav.php&#34;;
和example / index.php
内部包括&#34; ../ nav.php&#34 ;;