如何在我的面包屑上链接我的链接?

时间:2014-07-31 21:52:02

标签: php html mysql

我想知道如何在我的两个面包屑(顶部和底部)上链接我的所有链接,以便我可以知道我在我的网站上的位置?我希望例如当我转到我的页面rules.php时,我的面包屑上显示“规则”:http://prntscr.com/48anw3

这是我的结构:

index.php文件:

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta charset="UTF-8">
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "index") !== false) { ?>
        <title>Test - Forums</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "members") !== false) { ?>
        <title>Test - Members</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_up") !== false) { ?>
        <title>Test - Sign Up</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_in") !== false) { ?>
        <title>Test - Sign In</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "change_theme") !== false) { ?>
        <title>Test - Change Theme</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "contact_us") !== false) { ?>
        <title>Test - Contact Us</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "help") !== false) { ?>
        <title>Test - Help</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "rules") !== false) { ?>
        <title>Test - Rules</title>
        <?php } ?>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <?php include("top_bar.php");?>
        <?php include("header.php");?>
        <?php include("container.php");?>
        <?php include("footer.php");?>
    </body>
</html>

top_bar.php文件:

<!-- TOP BAR -->
<div id="top_bar">
    <div class="wrapper">
        <div id="top_bar_links">
            <ul>
            <?php
            $full_name = $_SERVER["PHP_SELF"];
            $name_array = explode("/",$full_name);
            $count = count($name_array);
            $page_name = $name_array[$count-1];
            ?>
            <li>
                <a id="home" href="../">Home</a>
            </li>
            <li>
                <a id="forums" class="<?php echo ($page_name=="index.php")?"active":"";?>" href=".">Forums</a>
            </li>
            <li>
                <a id="members" class="<?php echo ($page_name=="members.php")?"active":"";?>" href="members">Members</a>
            </li>
            </ul>
        </div>
    </div>
</div>

header.php文件:

<!-- HEADER -->
<div id="header">
    <div class="wrapper">
        <h1 id="logo">
            <a href=".">Test</a>
        </h1>
        <div id="member_links">
            <ul>
                <li>
                    <a id="sign_up" href="sign_up">Sign Up</a>
                </li>
                <li>
                    <a id="sign_in" href="sign_in">Sign In</a>
                </li>
            </ul>
        </div>
    </div>
</div>

container.php文件(放置我的面包屑的地方):

<!-- CONTAINER -->
<div class="wrapper">
    <div id="container">
        <div id="breadcrumb_top">
            <div class="breadcrumb_links">
                <ul>
                </ul>
            </div>
        </div>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "index") !== false) { ?>
        <h1 style="margin-bottom: 15px;">Forums</h1>
        <h3 id="category_title">Categories</h3>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "members") !== false) { ?>
        <h1 style="margin-bottom: 15px;">Members</h1>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_up") !== false) { ?>
        <h1 style="text-align: center; margin-bottom: 15px;">Sign Up</h1>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_in") !== false) { ?>
        <h1 style="text-align: center; margin-bottom: 15px;">Sign In</h1>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "change_theme") !== false) { ?>
        <h1 style="margin-bottom: 15px;">Change Theme</h1>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "contact_us") !== false) { ?>
        <h1 style="margin-bottom: 15px;">Contact Us</h1>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "help") !== false) { ?>
        <h1 style="margin-bottom: 15px;">Help</h1>
        <?php } ?>
        <?php if(strpos($_SERVER["SCRIPT_FILENAME"], "rules") !== false) { ?>
        <h1 style="margin-bottom: 10px;">Rules</h1>
        <p style="margin-bottom: 15px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu nibh turpis. Nunc sit amet auctor elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In malesuada lobortis tempus. Integer auctor condimentum sapien, non scelerisque eros cursus et. In vel leo elementum, iaculis tellus sit amet, vestibulum quam. Etiam dapibus pulvinar risus, vestibulum rhoncus sapien commodo vitae. Etiam sit amet ultrices dui. Suspendisse luctus fringilla eros. Nam vitae metus porttitor, sagittis arcu eleifend, malesuada odio. Aliquam erat volutpat.</p>
        <p style="margin-bottom: 15px;">Pellentesque id velit a elit porttitor sollicitudin et vulputate nisl. Donec eu purus non libero porta malesuada et non lorem. Vestibulum ultrices vitae elit vitae accumsan. Quisque euismod, quam sed ornare ultrices, magna mi posuere massa, vel placerat ipsum est quis erat. Aliquam non libero mauris. Etiam ligula velit, commodo et feugiat ac, porta eu orci. Donec laoreet ipsum in urna auctor, vitae malesuada nibh consequat. Donec sit amet libero vitae erat rhoncus venenatis. Maecenas nec pretium justo, eget fermentum tellus. Ut aliquet tellus venenatis posuere fermentum. Fusce mattis velit et tellus suscipit consectetur.</p>
        <?php } ?>
        <div id="breadcrumb_bottom">
            <div class="breadcrumb_links">
                <ul>
                </ul>
            </div>
        </div>
    </div>
</div>

.htaccess文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

我的网站http://nextgenfocus.com/

感谢那些将受到惩罚的人阅读问题并帮助我。

1 个答案:

答案 0 :(得分:0)

这里有面包屑的一些简单解决方案,

如果你使用htacces这个选项是一个很好的选择

$crumbs = explode("/",$_SERVER["REQUEST_URI"]);
foreach($crumbs as $crumb){
    echo ucfirst(str_replace(array(".php","_"),array(""," "),$crumb) . ' ');
}

取自: PHP Simple dynamic breadcrumb

如果你需要更具体的东西,很乐意帮忙:)

其他一些选择: http://www.phpro.org/classes/Breadcrumbs.html

http://pixelcode.co.uk/tutorials/php/breadcrumbscript-using-php/

------ ------- UPATE 这应该可以解决问题

<?php
if($location = substr(dirname($_SERVER['PHP_SELF']), 1))
    $dirlist = explode('/', $location);
else
    $dirlist = array();

$count = array_push($dirlist, basename($_SERVER['PHP_SELF']));

$address = 'http://'.$_SERVER['HTTP_HOST'];

echo '<a href="'.$address.'">Home</a>';

for($i = 0; $i < $count; $i++)
    echo '&nbsp;&raquo;&nbsp;<a href="'.($address .= '/'.$dirlist[$i]).'">'.ucfirst(str_replace(".php","",$dirlist[$i])).'</a>';
?>