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

Starting up and stopping Oracle Listener and iSqlPlus

Starting up and stopping Oracle's Listner Service and httpd service for iSqlPlus. I know it's a lame, but what the heck. Someone may be benefitted. In the last post I installed Oracle 9i on RHEL5. But my Oracle agent dint startup. Which mean I have to startup and stop aforementioned services manually till I could configure the Agent.  Well the commands are quite simple. To startup Oracle's Listner Service - $lsnrctl start To Stop the listner- $lsnrctl stop To start the httpd server for iSqlPlus -  $ORACLE_HOME/Apache/Apache/bin/apachectl start To stop the httpd server for iSqlPlus -  $ORACLE_HOME/Apache/Apache/bin/apachectl stop I have made two shell-script for these operation, just to ease my finger from over-typing. These files and their contents are: isqlplusstart.sh #[Content] lsnrctl start ORACLE_HOME/Apache/Apache/bin/apachectl start #[End Content] and isqlplusstop.sh #[Content] lsnrctl stop ORACLE_HOME/Apache/Apache/bin/apachectl stop #[End Content] I made them execu