OpenCart – Breadcrumbs

This article will be an in depth discussion on how the breadcrumbs work within the Opencart framework. Yet again, breadcrumbs are a procedure that most do not know anything about. They see them on the website but don’t know what to call them. Or, most have limited knowledge on the science behind them.

What are breadcrumbs?

Breadcrumbs or breadcrumb trail is a navigation aid used in user interfaces. It allows users to keep track of their locations within programs or documents. Breadcrumbs typically appear horizontally across the top of a web page, often below title bars or headers. They provide links back to each previous page the user navigated through to get to the current page or—in hierarchical site structures—the parent pages of the current one. Breadcrumbs provide a trail for the user to follow back to the starting or entry point. greater-than sign (>) often serves as hierarchy separator, although designers may use other glyphs (such as » or ›), as well as various graphical treatments. In layman’s terms you can think about a breadcrumb trail as a trail of web pages that you have just visited taking the form of active URL’s when clicked takes you to the specified page.

How do breadcrumbs work?

Breadcrumbs in Opencart are run entirely with PHP. Everything is done from within the Control File of that directory. For example, if we are going to place breadcrumbs on a category page then the breadcrumb code would be placed on this page: /catalog/controller/product/category.php.  If breadcrumbs are placed on the contact us page then the code would go here: /catalog/controller/information/contact.php

Let’s look at an example of the code that makes these breadcrumbs function. Open /catalog/controller/information/contact.php and find this line of code:

$this->data['breadcrumbs'] = array();

      	$this->data['breadcrumbs'][] = array(
        	'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),        	
        	'separator' => false

      	$this->data['breadcrumbs'][] = array(
        	'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('information/contact'),
        	'separator' => $this->language->get('text_separator')

We start with creating an array called bread crumbs: $this->data[‘breadcrumbs’] = array();

We then add ON to that array with another array or array(s). Each additional array is another breadcrumb like this:

$this->data[‘breadcrumbs’][] = array(
            ‘text’      => $this->language->get(‘text_home’),
            ‘href’      => $this->url->link(‘common/home’),            
            ‘separator’ => false //FIRST BREADCRUMB SO FALSE ICON

          $this->data[‘breadcrumbs’][] = array(
            ‘text’      => $this->language->get(‘heading_title’), //TITLE
            ‘href’      => $this->url->link(‘information/contact’), //NOTICE THE LINK SET UP HERE
            ‘separator’ => $this->language->get(‘text_separator’)//SEPERATOR ICON

This will be displayed on the HTML page or (.tpl page) by simply echoing the variable. If you open up the contact us page you will see this line: <?php echo $breadcrumbs;?>

Once this is echoed it will end up looking like this:


Looking for quality OpenCart Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , | Posted under OpenCart | RSS 2.0

Author Spotlight

Joe Stenhouse

I am a web application developer that specializes in PHP, JAVASCRIPT, MYSQL, HTML, and CSS. We manifest exciting potentials within the world wide web through means of innovation.

One Comment on OpenCart – Breadcrumbs

  1. Avinash says:

    Thank You…

Leave a Reply

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