Jump to content

bread crumb navigation


vbnullchar

Recommended Posts

There you go hope it will help you

<?php
$id = $_GET['id'];
if ( strlen( $id ) < 1 )
$id = "home";

$pages = array(
home => array( id=>"home", parent=>"", title=>"Home",
url=>"showpage.php?id=home" ),
users => array( id=>"users", parent=>"home", title=>"Users",
url=>"showpage.php?id=users" ),
jack => array( id=>"jack", parent=>"users", title=>"Jack",
url=>"showpage.php?id=jack" )
);

function breadcrumbs( $id, $pages )
{
  $bcl = array( );
  $pageid = $id;
  while( strlen( $pageid ) > 0 )
  {
$bcl[] = $pageid;
$pageid = $pages[ $pageid ]['parent'];
  }
  for( $i = count( $bcl ) - 1; $i >= 0; $i-- )
  {
$page = $pages[$bcl[$i]];
if ( $i > 0 )
{
echo( "<a href=\"" );
echo( $page['url'] );
echo( "\">" );
}
echo( $page['title'] );
if ( $i > 0 )
{
echo( "</a> | " );
}
  }
  }
  ?>
  <html>
  <head>
  <title>Page - <?php echo( $id ); ?></title>
  </head>
  <body>
  Breadcrumbs: <?php breadcrumbs( $id, $pages ); ?><br/>
  Page name: <?php echo( $id ); ?>
  </body>
  </html>
[quote author=vbnullchar link=topic=111046.msg449746#msg449746 date=1160477889]
still no. 

I wanted to create a navigation similar to this, where you can just click the previous level

PHP Freaks Forums > PHP and MySQL > PHP Help > bread crumb navigation
[/quote]

OK, I don't know if you didn't read the page where I sent you or just didn't understand, but the link I posted was to some code for breadcrumb navigation that allows you to click the previous levels.  There were even over 25 examples when showing the different options with the code.

I think I'm going to have to bail out of this one, good luck with finding what you're after

Regards
Huggie
Store the bread crumbs in an array like this: [code]$nav[] = array('Main page','index.php');
$nav[] = array('Some other page','index.php?page=some_other');
$nav[] = array('Yet another page');[/code]

Then when generating the bread crumbs do this: [code]<?php
foreach($nav as $bc)
{
$nav2[] = empty($bc[1]) ? $bc[0] : "<a href='{$bc[1]}'>{$bc[0]}</a>";
}

echo "<div id='bread_crumbs'>".join(' &gt; ',$nav2)."</div>";
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.