PHP Breadcrumb – Create breadcrumb in php

What are breadcrumbs?

Well quite simply, in web page terms this refers to a list of links (usually at the top) that appear on a web page to tell the user where they are in the structure of the website they are viewing. This makes navigating backward and forward so much easier as they have the ability to skip directly back through whole categories, rather than just using the browser’s back button.

Example

The breadcrumbs.php include file:

Copy the code below, save it in a file called breadcrumbs.php and upload it to your site. This will print out a simple unordered list (<ul>) of the parent directories by directory name. The only edits you may wish to make to this file is to change the $ul_id='crumbs'; line if you wish to change the id of the <ul>. If you wish to add a background image or border etc to the <li> simply select it as #crumbs li{} and style.


</code><?
$ul_id='crumbs';
$bc=explode("/",$_SERVER["PHP_SELF"]);
echo '<ul id="'.$ul_id.'"><li><a href="/">Home</a></li>';
while(list($key,$val)=each($bc)){
 $dir='';
 if($key > 1){
  $n=1;
  while($n < $key){
   $dir.='/'.$bc[$n];
   $val=$bc[$n];
   $n++;
  }
  if($key < count($bc)-1) echo '<li><a href="'.$dir.'">'.$val.'</a></li>';
 }
}
echo '<li>'.$pagetitle.'</li>';
echo '</ul>';</pre>
?>   This is some more usefull code
<pre><?
$url = $_SERVER['REQUEST_URI'];
echo $url;
echo "<br>";
$array = explode("/",$url);
echo $array[2]; ///which folder would you want to access ?
echo "size of array = ".sizeof($array)."<br>";
?><code>

A script to insert in the HTML where you want the breadcrumbs to appear:

Edit the URI to point to where you saved the include file (once this is done it never needs to be changed again). Edit, ‘Insert Page Title’ to add the page title to the end of the breadcrumbs.


</code><?
$pagetitle="Insert Page Title";
include("http://www.yourdomain.com/breadcrumbs.php");
?>

Note: It would be useful to automatically print the page <title> as the last crumb but PHP cannot interogate the DOM. Javascript would be required which we didn't think appropriate as nothing would be returned if Javascript was turned off.

You may like following Articles!

This entry was posted in PHP and tagged , , by Wordpress API. Bookmark the permalink.

About Wordpress API

API means Application Program interface. In Wordpress API we are giving all the information about wordpress API. We worked for many wordpress plugins and themes. We have expertise in PHP, Databases, Graphic Design, Ruby on Rails, Java, Wordpress, Drupal and many CMS. We always give you the best solutions about wordpress and other related topics in This Blog. We will give you always fresh tips and tricks and techniques about wordpress in this blog.

25 thoughts on “PHP Breadcrumb – Create breadcrumb in php

  1. Superb posting, this is very similar to a site that I have. Please check it out sometime and feel free to leave me a comenet on it and tell me what you think. I’m always looking for feedback.

  2. I don’t agree with everything in this article, but you do make some very good points. Im very interested in this subject matter and I myself do alot of research as well. Either way it was a well thoughtout and nice read so I figured I would leave you a comment. Feel free to check out my website sometime and let me know what you think.

  3. This is a good article, I was wondering if I could use this piece of writing on my website, I will link it back to your website though. If this is a problem please let me know and I will take it down right away.

  4. This is a good write-up, I was wondering if I could use this piece on my website, I will link it back to your website though. If this is a problem please let me know and I will take it down right away.

  5. You areawesome! This blog is really good. I truly hope a lot more men and women examine this and get what youre declaring, simply because let me tell you, its crucial stuff. I under no circumstances wouldve considered about it by doing this unless Id operate into your blog. Thanks for placing it up. I wish you might have fantastic accomplishment.

  6. Thanks for taking the time to talk about this, I feel fervently about this and I take pleasure in learning about this topic. Please, as you gain information, please update this blog with more information. I have found it very useful.

  7. Nice post! You truly have a wonderful way of writing which I find captivating! I will definitely be bookmarking you and returning to your blog. In fact, your post reminded me about a strange thing that happened to me the other day. I’ll tell you about that later…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>