我为我们的网站创建了一个breacrumb功能,但遇到了一个小问题。 执行面包屑功能时,第一个孩子是空的。
我可以用css隐藏它。但我希望它是完美的。
function breadcrumbs() {
// Define urls
$home_url = URL;
$current_url = http:/example.com/index.php?folder=Salestijgers&sub_dir_1=Naamloze%20map%202&sub_dir_2=Afbeeldingen%20website;
$all_query = $_GET;
$count_query = count( $all_query );
$last_query = str_replace( '%20', ' ', substr( $current_url, strrpos( $current_url, '=' ) + 1 ) ); // Last query
$breadcrumbs = array(
$current_url
);
for( $i = 2; $i <= $count_query; $i++ ) {
$last = substr( $current_url, strrpos( $current_url, '&' ) ); // Last query
$new_url = str_replace( $last, '', $current_url );
$current_url = $new_url;
$breadcrumbs[] = $current_url;
}
krsort( $breadcrumbs );
$count_links = count( $breadcrumbs );
$current_page= "<li order=\"last-child\"><span>$last_query</span></li>";
for( $i = $count_links; $i >= 1; $i-- ) {
$title = str_replace( '%20', ' ', substr( $breadcrumbs[$i], strrpos( $breadcrumbs[$i], '=' ) + 1 ) );
$url .= "<li order=\"$i\"><a order=\"$i\" href=\"{$breadcrumbs[$i]}\" title=\"$title\">$title</a><i class=\"fa fa-angle-right\"></i></li>";
}
if( isset( $_GET['folder'] ) ) {
return $url . $current_page;
} else {
return "<li class=\"dont-hide\"><span>Mijn bestanden</span></li>";
}
}
我希望输出如下
Mijn bestanden &gt;&gt; 销售人员&gt;&gt; Naamloze地图&gt;&gt; Afbeeldingen网站
*粗体是链接,不是粗体是当前页面
我希望你们能帮助我!
答案 0 :(得分:0)
Use $breadcrumbs = array_filter( $breadcrumbs );
to filter out empty entries.