コード例 #1
0
 /**
  * Get post ancestors - used in breadcrumbs etc
  * Note posts can have multiple and divergent ancestory
  * @return (Array) Post ancestors
  */
 function ht_kb_get_ancestors()
 {
     global $post, $cat, $hkb_current_article_id;
     $ancestors = array();
     //path number
     $i = 0;
     $ancestors[$i] = array();
     if (!ht_kb_is_ht_kb_front_page()) {
         $taxonomy = ht_kb_get_taxonomy();
         $term_string = ht_kb_get_term();
         $visited = array();
         if (!empty($taxonomy) && !empty($term_string)) {
             //category terms bread crumb
             //add home link to path
             $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
             //kb archive set as home test
             if (!hkb_is_kb_set_as_front()) {
                 //add knowledge base to path
                 $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
             }
             $term = get_term_by('slug', $term_string, $taxonomy);
             if ($term == false) {
                 return;
             }
             if ($term->parent != 0) {
                 //has parents
                 $parents = $this->ht_get_custom_category_ancestors($term->term_id, 'ht_kb_category', true, null, false, $visited, $ancestors, $i);
                 //itself
                 //$ancestors[$i][] = array('label'=>$term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title'=>sprintf( __( "View all posts in %s" ), $term->name), 'type'=>'kb_current_page');
             } else {
                 //path
                 //add knowledge base to path
                 $ancestors[$i][] = array('label' => $term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title' => sprintf(__("View all posts in %s"), $term->name), 'type' => 'kb_tax');
                 $visited[] = $term->term_id;
             }
         } elseif (!is_single() && 'ht_kb' == get_post_type()) {
             //add home link to path
             $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
             //Archive
             $ht_kb_data = get_post_type_object('ht_kb');
             //kb archive set as home test
             if (!hkb_is_kb_set_as_front()) {
                 $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
             }
             //search?
             if (ht_kb_is_ht_kb_search()) {
                 $ancestors[$i][] = array('label' => __('Search Results', 'ht-knowledge-base'), 'link' => '', 'title' => __('Search Results', 'ht-knowledge-base'), 'type' => 'kb_search');
             }
         } elseif (is_single() && 'ht_kb' == get_post_type()) {
             //Single post
             $hkb_current_article_id = empty($hkb_current_article_id) ? get_the_ID() : $hkb_current_article_id;
             $terms = wp_get_post_terms($hkb_current_article_id, 'ht_kb_category');
             if (!empty($terms)) {
                 foreach ($terms as $term) {
                     //add home link to path
                     $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
                     //kb archive set as home test
                     if (!hkb_is_kb_set_as_front()) {
                         //add knowledge base to path
                         $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
                     }
                     if ($term->parent != 0) {
                         $parents = $this->ht_get_custom_category_ancestors($term->term_id, 'ht_kb_category', true, null, false, $visited, $ancestors, $i);
                         //itself
                         //$ancestors[$i][] = array('label'=>$term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title'=>sprintf( __( "Viewing a post in %s" ), $term->name), 'type'=>'kb_current_page');
                     } else {
                         //add knowledge base to path
                         $ancestors[$i][] = array('label' => $term->name, 'link' => esc_attr(get_term_link($term, 'ht_kb_category')), 'title' => sprintf(__("View all posts in %s"), $term->name), 'type' => 'kb_tax');
                         $visited[] = $term->term_id;
                     }
                     //itself
                     $ancestors[$i][] = array('label' => get_the_title(), 'link' => get_permalink(), 'title' => get_the_title(), 'type' => 'kb_current_page');
                     //increment the counter
                     $i++;
                 }
                 // End foreach
             } else {
                 //add home link to path
                 $ancestors[$i][] = array('label' => __('Home', 'ht-knowledge-base'), 'link' => home_url(), 'title' => __('Home', 'ht-knowledge-base'), 'type' => 'blog_home');
                 //kb archive set as home test
                 if (!hkb_is_kb_set_as_front()) {
                     //add knowledge base to path
                     $ancestors[$i][] = array('label' => __('Knowledge Base', 'ht-knowledge-base'), 'link' => get_post_type_archive_link('ht_kb'), 'title' => __('Knowledge Base', 'ht-knowledge-base'), 'type' => 'kb_home');
                 }
                 //uncategorized article
                 $ancestors[$i][] = array('label' => get_the_title(), 'link' => get_permalink(), 'title' => get_the_title(), 'type' => 'kb_current_page');
                 $i++;
             }
         } else {
             //Display the post title.
             $ancestors[$i][] = array('label' => get_the_title(), 'link' => get_permalink(), 'title' => get_the_title(), 'type' => 'kb_current_page');
             $i++;
         }
     }
     //is_front_page
     return $ancestors;
 }
コード例 #2
0
 /**
  * Get top level archive taxonomy terms for the Knowledge Base archive
  * @param (Int) $columns Number of columns
  * @param (Int) $sub_cat_depth Depth of subcategories to display
  * @param (Bool) $display_sub_cat_count Display a count in subcategories
  * @param (Bool) $display_sub_cat_articles Display/list subcategory articles
  * @param (String) $sort_by How to sort the archive
  * @param (String) $sort_order Sort order
  * @param (Bool) $hide_empty_kb_categories Whether to hide empty categories
  * @param (Int) $i Counter
  * @return (Array) Category terms
  */
 function hkb_get_master_tax_terms($columns = 2, $sub_cat_depth = 2, $display_sub_cat_count = true, $display_sub_cat_articles = true, $sort_by = 'date', $sort_order = 'asc', $hide_empty_kb_categories = false)
 {
     global $ht_kb_display_archive, $ht_knowledge_base_options, $hkb_master_tax_terms;
     //set user options
     $columns = array_key_exists('archive-columns', $ht_knowledge_base_options) ? $ht_knowledge_base_options['archive-columns'] : $columns;
     $sub_cat_display = array_key_exists('sub-cat-display', $ht_knowledge_base_options) ? $ht_knowledge_base_options['sub-cat-display'] : $sub_cat_display;
     $sub_cat_depth = array_key_exists('sub-cat-depth', $ht_knowledge_base_options) ? $ht_knowledge_base_options['sub-cat-depth'] : $sub_cat_depth;
     $display_sub_cat_count = array_key_exists('sub-cat-article-count', $ht_knowledge_base_options) ? $ht_knowledge_base_options['sub-cat-article-count'] : $display_sub_cat_count;
     $display_sub_cat_articles = array_key_exists('sub-cat-article-display', $ht_knowledge_base_options) ? $ht_knowledge_base_options['sub-cat-article-display'] : $display_sub_cat_articles;
     $hide_empty_kb_categories = array_key_exists('hide-empty-kb-categories', $ht_knowledge_base_options) ? $ht_knowledge_base_options['hide-empty-kb-categories'] : $hide_empty_kb_categories;
     //list terms in a given taxonomy
     $args = array('orderby' => 'term_order', 'depth' => 0, 'child_of' => 0, 'hide_empty' => $hide_empty_kb_categories, 'pad_counts' => true);
     $hkb_master_tax_terms = get_terms('ht_kb_category', $args);
     //limit depth if archive display or front page
     if ($this->is_ht_kb_archive || ht_kb_is_ht_kb_front_page()) {
         $hkb_master_tax_terms = $this->hkb_filter_terms_by_depth($hkb_master_tax_terms, $sub_cat_depth);
     }
     return $hkb_master_tax_terms;
 }