Skip to main content

Custom breadcrumb list in wordpress

While developing a custom plugin for a website I needed to post a custom breadcrumb trail.

Articles on this website are based on a custom post type and some of them were very deep in hierarchical order.  (Example : Knowledgebase > Indian Mining Regulations > DGMS > Mining Legislation > Safety Conferences on Safety in Mines > X - Safety Conference)

I wanted to put a series of links for visitor to follow the progression of contents. So, I thought about giving them breadcrumb trails to follow it back to wherever they want to go in the series. After some google search and some modifications: here is what I created. Hope, it may help you. This is for a custom post type of hierarchical in nature, but it can also be used for pages or other post types having hierarchies.


function fn_nova_breadcrumb_trail($post)
{
$separator = '  > ';
$trail_posts = array($post);
$parent = $post;
$current_post_id=$post->ID;
while($parent->post_parent)
{
  $parent = get_post( $parent->post_parent );
  array_unshift( $trail_posts, $parent );
}
$str_return='';
foreach($trail_posts as $trail_post)
{
  $trail_post_id=$trail_post->ID;
 
if($current_post_id==$trail_post_id)
{
$str_return.= $separator.$trail_post->post_title;
}
else
{
$str_return.= $separator.'<a href="'.get_permalink($trail_post_id).'">'.$trail_post->post_title.'</a>';
}
}
return $str_return;
}

If need be, you can easily convert this into a nice shortcode. You can also support custom taxonomies.

Ref. WordPress Breadcrumb Navigation

Comments

Popular posts from this blog

Installing Oracle 9i on RHEL5. (x86)

I must warn you that this article is as it is. It worked when I was installing the combo - a long time ago. I am not sure about the links available in this article. I am not maintaining this article anymore, (other than sprucing it up a bit for better reading). I am completely out of touch with RHEL or Oracle for that matter. Still, dont lose your heart yet. I am sure, with proper searching using the big brother - Google, you will find lots of more information relating to your work to help you finish what you are doing. Foreword Recently I joined Sqlstar International for my Oracle DBA course. Everything was going smooth. I completed my SQL Fundamentals with Oracle installed on Windows in my pc. But when classes started for DBA Fundamentals 1 I was at loss, as in my institute oracle was installed on Redhat Linux platform. I could have done all the solution of the text on windows but I decided to configure my own Linux box and install oracle on it to simulate the class environment.

Datatables and Wordpress Integration problem solved.

Note: Download a working demo plugin from this project's github repository . Like other wordpress developers, I had also faced the problem of integrating datatable (server side processing) with wordpress. I tried every tips, tricks and multiple ways to solve the problem, but couldn't do it. My ajaxified functions of the wordpress simple dint work. I din't have much time and had to finish a small project on time. So, I decided to skip it and go through the developer's way : the plugin developer had suggested and implemented. I dropped the required php file with some related modifications and called the url of the php file in the datatable options in my project. It worked after few small hiccups. I wasn't satisfied though, as i wanted the wordpress centric solution, instead of using some drop-in file to complement the functionality. I had vowed to look after this problem whenever I could get some time. (You may visit the url http://www.bearinghouse.net/orde

Web Development Dilemma - Part 2

Recently, I got a Job to build an ERP Application (More like Accounting Package with CRM). I started planning for the Application. I had some experience with Tally.ERP 9 and knew a bit about Accounting too. Once again I chose Wordpress Platform for the application development, as I was more comfortable with it. Application was to have multiple advanced features along with some of smart automated data sensing and processing, and selective data push (Semi-Automated) to Tally for Accounting Purpose. The application was to run in a LAN Environment and was connected with the Customer's Website to retrieve Customer Order submitted on the website (Customized Shopping Cart) for further processing.  I could develop fast in Wordpress, I was familiar with the system and environment. But due to multiple distractions, and tedious job (I hadn't anticipated lengthy coding and timing involved), the project had to be scrapped by the customer. The customer was gracious enough to forgive me