开发者

PHP: breadcrumb path?

开发者 https://www.devze.com 2023-01-07 00:54 出处:网络
i wonder if you could help me building a little breadcrumb path with php. print $path; // /folder/subfolder/subfolder/etc

i wonder if you could help me building a little breadcrumb path with php.

        print $path; // /folder/subfolder/subfolder/etc
    // breadcrumb path
    $crumb = explode("/", $path);
    print "<div class='breadcrumbs'>";
    foreach($crumb as $value) {
        print "<a href='?p=". $va开发者_开发问答lue ."'>$value</a> &gt; ";
    }
    print "</div>";

the breadcrumbs get printed exactly the way i want them, however i've no idea how i could link every breadcrumb to it's relative path.

e.g. if the current $path is /folder/subfolder/subfolder/etc the the first link (folder) would link to ?p=folder, the second link (subfolder) would link to ?p=subfolder and so on. however the second link has to be ?p=folder/subfolder and not just ?p=folder.

any idea how i could solve that?


$crumb = explode("/", $path);
print "<div class='breadcrumbs'>";
$newpath = '';
foreach($crumb as $value) {
    $newpath .= $value;
    print "<a href='?p=". $newpath ."'>$value</a> &gt; ";
    $newpath .= '/';
}
print "</div>";
0

精彩评论

暂无评论...
验证码 换一张
取 消