/**
  * Returns the wrapper element if it exists including specified id, class, 
  * microdata, prefix and suffix.
  * 
  * @access public
  * @param bool $open_tag (default: true) Whether or not to output the opening or closing tag
  * @return string
  */
 public function display($open_tag = true)
 {
     $element = HAG_Utils::sanitize_element($this->options['wrapper_element']);
     if (empty($element) && $open_tag) {
         return $this->options['prefix'];
     }
     if (empty($element) && !$open_tag) {
         return $this->options['suffix'];
     }
     if (!$open_tag) {
         return sprintf('%s</%s>', $this->options['suffix'], $element);
     }
     $class = HAG_Utils::sanitize_class($this->options['wrapper_class']);
     $id = HAG_Utils::sanitize_class($this->options['wrapper_id']);
     $wrapper = array();
     $wrapper[] = sprintf('<%s', $element);
     if (!empty($id)) {
         $wrapper[] = sprintf('id="%s"', $id);
     }
     if (!empty($class)) {
         $wrapper[] = sprintf('class="%s"', $class);
     }
     if ($this->options['microdata']) {
         $wrapper[] = 'itemprop="breadcrumb"';
     }
     $wrapper[] = sprintf('>%s', $this->options['prefix']);
     return implode(' ', $wrapper);
 }
 /**
  * Gets the crumbs for a single, non-archive post/page.
  *
  * @access private
  * @static
  * @param array $options
  * @return array
  */
 private static function get_singular_crumbs(array $options)
 {
     $post = get_queried_object();
     if (is_null($post)) {
         $post = $GLOBALS['post'];
     }
     $crumbs = array();
     $pt = get_post_type_object($post->post_type);
     if (!is_null($pt) && !is_wp_error($pt) && $pt->has_archive && $options['post_type_show']) {
         $crumbs[] = new HAG_Crumb($options, $pt->label, get_post_type_archive_link($pt->name), false, false);
     }
     $rev_crumbs = array();
     if ($options['last_show']) {
         $rev_crumbs[] = new HAG_Crumb($options, get_the_title($post->ID), get_permalink($post->ID), false, true);
     }
     if (is_post_type_hierarchical($pt->name)) {
         foreach ($post->ancestors as $aID) {
             $ancestor = get_post($aID);
             $rev_crumbs[] = new HAG_Crumb($options, $ancestor->post_title, get_permalink($ancestor->ID), false, false);
         }
     } elseif ($options['taxonomy_show']) {
         $tax_names = get_object_taxonomies($post);
         $taxes = get_object_taxonomies($post->post_type, OBJECT);
         $term_args = array('orderby' => 'count', 'order' => 'DESC');
         $term = null;
         //get preferred taxonomy term if it exists
         if (in_array($options['taxonomy_preferred'], $tax_names)) {
             $tax_name = $options['taxonomy_preferred'];
             $tax = array_key_exists($tax_name, $taxes) ? $taxes[$tax_name] : null;
             if (!is_null($tax)) {
                 $terms = HAG_Utils::get_filtered_object_terms($post->ID, $tax_name, $term_args, $options);
             }
             if (count($terms) > 0) {
                 $term = $terms[0];
             }
         }
         //else, get hierarchical taxonomy term if it exists
         if (is_null($term)) {
             $hier_taxes = array();
             foreach ($taxes as $t) {
                 if ($t->hierarchical) {
                     $hier_taxes[] = $t->name;
                 }
             }
             $hier_terms = HAG_Utils::get_filtered_object_terms($post->ID, $hier_taxes, $term_args, $options);
             if (!is_wp_error($hier_terms) && count($hier_terms) > 0) {
                 $term = $hier_terms[0];
             }
         }
         //else, get non-hierarchical taxonomy term if it exists
         if (is_null($term)) {
             $unhier_taxes = array();
             foreach ($taxes as $t) {
                 if (!$t->hierarchical) {
                     $unhier_taxes[] = $t->name;
                 }
             }
             $unhier_terms = HAG_Utils::get_filtered_object_terms($post->ID, $unhier_taxes, $term_args, $options);
             if (!is_wp_error($unhier_terms) && count($unhier_terms) > 0) {
                 $term = $unhier_terms[0];
             }
         }
         if (!is_null($term)) {
             do {
                 $rev_crumbs[] = new HAG_Crumb($options, $term->name, get_term_link($term), false, false);
                 $term = get_term($term->parent, $term->taxonomy);
             } while (!is_wp_error($term) && $options['taxonomy_ancestors_show']);
         }
     }
     return array_merge($crumbs, array_reverse($rev_crumbs));
 }
 /**
  * Outputs the breadcrumbs based on the specified options (resolved
  * against the saved and plugin defaults).
  *
  * @access public
  * @static
  * @param array $options (default: null)
  * @return void
  */
 public static function display(array $options = null)
 {
     /******************************************************** RESOLVE POST TYPE */
     $post = get_queried_object();
     $post_type = '';
     if (is_single()) {
         $post_type = $post->post_type;
     } elseif (is_post_type_archive()) {
         $post_type = $post->name;
     }
     /***************************** LOAD AND RESOLVE OPTIONS FOR THE BREADCRUMBS */
     if (!is_array($options)) {
         $options = array();
     }
     $options = HAG_Options::get_options($options, $post_type);
     /*************************************** PRINT DEBUG INFORMATION IF DESIRED */
     if ($options['debug_show']) {
         HAG_Utils::debug_info($options, $options['debug_comment']);
     }
     /************************************* OBTAIN CRUMBS AND EXIT IF NONE FOUND */
     $crumbs = HAG_Crumb::get_crumbs($options);
     if (0 === count($crumbs)) {
         return;
     }
     /********************************************* BUILD OUTPUT BASED ON OPTIONS*/
     $wrapper = new HAG_Wrapper($options);
     $output = array();
     $output[] = $wrapper->display(true);
     $output[] = implode(sprintf('%s', $options['separator']), $crumbs);
     $output[] = $wrapper->display(false);
     echo implode('', $output);
 }