문제

I'm creating a dynamic breadcrumb menu, it's grabbing the url and outputting each directory to the end user correctly but for example if you click the first breadcrumb link after home, it's still using the FULL url and also adding 'array to the end too'. I'll post the code below to make some send of this and screenshots.

PHP/HTML

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

<div class="breadcrumb">
    <ul>
        <li><a href="<?php HTTP_HOST ?>">Home</a></li>
        <?php foreach($crumbs as $crumb){ ?>
            <li><a href="<?php echo $crumbs; ?>"><?php echo $crumb; ?></a></li>
        <?php } ?>
    </ul>
</div>

How it appears so far:

enter image description here


The link which it tried to load when I clicked In-House-Training for an example.

enter image description here

도움이 되었습니까?

해결책

You're generating your URL wrong. Notice how you're echoing $crumbs array into a href attribute. You should start your url with your site root url and on every foreach loop pass, add appropriate piece of string

$url = "http://www.yoursite.com";

<div class="breadcrumb">
    <ul>
        <li><a href="<?php echo $url ?>">Home</a></li>
        <?php foreach($crumbs as $crumb){
          $url .= "/".$crumb;
        ?>
            <li><a href="<?php echo $url; ?>"><?php echo $crumb; ?></a></li>
        <?php } ?>
    </ul>
</div>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top