I'm makeing dynamic bredcrumbs based on current url i have. My problem is, that i can't figure out how to generate right link and attach it to word, because of foreach loop. My code is realy messy, so i whould realy need a help. Hope you guys can help!
Tnx
Here is my code:
<?php
$url = current_url();
$home = "www.homepage.com";
$sub_url = substr($url, strpos($url, $home));
$segments = explode("/", $url);
$parts = array_slice($segments, 3);
$count = count($parts);
$i = 0;
?>
//Don't show breadcrumb on home page
<?php if (current_url() !== base_url() && current_url() !== base_url() . "home") { ?>
<div class="breadcrumbs">
<a href="<?php echo base_url(); ?>"><div class="home">Home</div></a>
<div class="divider1"></div>
<?php
foreach ($parts as $row) {
$bread = ucfirst(str_replace("-", " ", str_replace("_", " ", $row)));
?>
<div class="level1" style="margin-left: -6px ;">
<a href="#"><?php echo $bread." ". $i; ?></a>
</div>
<?php if ($i < $count - 1) { ?>
<div class="divider1"></div>
<?php
}
$i++;
}
?>
</div>
<?php } ?>
EDIT: Right link means if you have url like www.homepage.com/mens_where/mens_jackets/Jacket123
Output should be something like that if i don't consider echo-ing classes in upper code
<a href="www.homepage.com">home</a>
<a href="www.homepage.com/mens_wear">Mens Wear</a>
<a href="www.homepage.com/mens_wear/mens_jackets">Mens jackets</a>
<a href="www.homepage.com/mens_wear/mens_jackets/Jacket123">Jacket123</a>