2016-03-04 104 views
-2

爲我們的網站創建一個breacrumb函數,但遇到一個小問題。 執行面包屑功能時,第一個孩子是空的。從查詢字符串創建PHP Breadcrumbs

我可以用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 >>Salestijgers >>Naamloze地圖 >> Afbeeldingen網站

*粗體是鏈接,而不是大膽的是當前頁面

我希望你們能幫助我!

回答

0

使用$breadcrumbs = array_filter($breadcrumbs);過濾掉空條目。