Hello! I have a website based on mysql. Interested in How to make bread crumbs in php (such as this: Home> News> Weather ... etc.)? There are a lot of such cms in the internet for cms, and I have a self-written site. I will be glad to any help. Thank.
- oneAs an option - to observe the parent, using which to display the name of the page! In general, if the system is normally thought out, the writing is easy to implement ... If the writing is not thoroughly implemented, you need to always implement it! - Palmervan pm
- oneIt is clear, thank you) - qwerty17
- oneWhat kind of crazy thing came up with such a thing? - SverxnovA 4:39 pm
- 2@SverxnovA Brothers Grimm. - PashaPash ♦
3 answers
Once did a long time.
Crumble handler:
function navigation() { $arg_list = func_get_args(); $numargs = func_num_args(); $str = ''; for ($i = 0; $i < $numargs; $i++) { $str .= ($arg_list[$i][1] ? ($arg_list[$i][0] ? '<a href="' . $arg_list[$i][0] . '">' . $arg_list[$i][1] . '</a>' : $arg_list[$i][1] ) . ($numargs - 1 > $i && $arg_list[$i][0] ? '<span>›</span>' : '' ) : '' ); } return $str; }
Using:
echo navigation( array('/', 'Главная'), array('/old', 'Чуток ниже'), array('/old-s', 'И еще чуток ниже') );
Result:
<a href="/">Главная</a><span>›</span><a href="/old">Чуток ниже</a><span>›</span><a href="/old-s">И еще чуток ниже</a>
Naturally, the HTML code can be changed as needed.
Yes, the function is curve and bla bla bla. Another Messi scored 5 goals, yeah.
Once done using Nested Sets . Advantage - it is not necessary for each parent to ask the parent or to drag the whole bunch of id-sons with you, but only knowing 1 id get the whole branch at once
//Определяем переменную parent_id $parent_id = isset($_GET['parent_id']) ? $_GET['parent_id'] : null; function breadcrumb($cat, $parent_idid){ //Проверяем что parent_ID это число if(!intval($parent_idid)) return false; //Создаем пустой массив $brc = array(); //Перебираем полученый массив с меню for($i = 0; $i < count($cat); $i++){ //Проверяем что мы не нашли родителя и не массив пуст if($parent_id != 0 and !empty($cat[$parent_id])){ //Ищем родителя $brc[$cat[$id]['parent_id']] = $cat[$parent_id]['title']; $parent_id = $cat[$parent_id]['parent']; } //Останавливаем цикл else break; } //Возвращаем перевернутый массив с сохранением ключей return array_reverse($brc, true); }
Protected by spirit community member ♦ Oct 9 '15 at 21:08 .
Thank you for your interest in this issue. Since he collected a large number of low-quality and spam responses, which had to be deleted, now it’s necessary to have 10 reputation points on the site (the bonus for account association is not counted ).
Maybe you want to answer one of the unanswered questions ?