Example #1
0
/**
* Get array of term objects parents of the term passed
*
* @param mixed $term
* @access public
* @return array Array of term objects ordered in a hierarchical way including
* the term passed as an argument
*/
function get_dr_term_parents($term)
{
    static $terms = array();
    array_unshift($terms, $term);
    if (!empty($term->parent)) {
        get_term_parents(get_term($term->parent, $term->taxonomy));
    }
    return $terms;
}
 function get_term_parents($term, &$parents = array())
 {
     $parent = get_term($term->parent, $term->taxonomy);
     if (is_wp_error($parent)) {
         return $parents;
     }
     $parents[] = $parent;
     if ($parent->parent) {
         get_term_parents($parent, $parents);
     }
     return $parents;
 }
 /**
  * Generic version of standard permalink parsing function. Adds support for
  * custom taxonomies as well as the standard %author% etc...
  *
  * @param string $post_link The post URL
  * @param object $post      The post object
  * @param bool $leavename Passed to pre_post_link filter
  * @param bool $sample    Used in admin if generating an example permalink
  *
  * @return string    The parsed permalink
  */
 public function parse_permalinks($post_link, $post, $leavename, $sample = false)
 {
     $id = $post->ID;
     $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%author%', $leavename ? '' : '%pagename%');
     $taxonomies = get_object_taxonomies($post->post_type);
     foreach ($taxonomies as $taxonomy) {
         $rewritecode[] = '%' . $taxonomy . '%';
     }
     if (is_object($post) && isset($post->filter) && 'sample' == $post->filter) {
         $post = $post;
         $sample = true;
     } else {
         $post = get_post($id);
         $sample = false;
     }
     $post_type = get_post_type_object($post->post_type);
     $permastruct = get_option($post_type->name . '_permalink_structure');
     // prefer option over default
     if ($permastruct && !empty($permastruct)) {
         $permalink = $permastruct;
     } elseif (isset($post_type->rewrite['permastruct']) && !empty($post_type->rewrite['permastruct'])) {
         $permalink = $post_type->rewrite['permastruct'];
     } else {
         return $post_link;
     }
     $permalink = apply_filters('pre_post_link', $permalink, $post, $leavename);
     if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
         $unixtime = strtotime($post->post_date);
         // add ability to use any taxonomies in post type permastruct
         $replace_terms = array();
         foreach ($taxonomies as $taxonomy) {
             $term = '';
             $taxonomy_object = get_taxonomy($taxonomy);
             if (strpos($permalink, '%' . $taxonomy . '%') !== false) {
                 $terms = get_the_terms($post->ID, $taxonomy);
                 if ($terms) {
                     usort($terms, '_usort_terms_by_ID');
                     // order by ID
                     $term = $terms[0]->slug;
                     if ($taxonomy_object->hierarchical && ($parent = $terms[0]->parent)) {
                         $term = get_term_parents($parent, $taxonomy, false, '/', true) . $term;
                     }
                 }
                 // show default category in permalinks, without
                 // having to assign it explicitly
                 if (empty($term) && $taxonomy == 'category') {
                     $default_category = get_category(get_option('default_category'));
                     $term = is_wp_error($default_category) ? '' : $default_category->slug;
                 }
             }
             $replace_terms[$taxonomy] = $term;
         }
         $author = '';
         if (strpos($permalink, '%author%') !== false) {
             $authordata = get_userdata($post->post_author);
             $author = $authordata->user_nicename;
         }
         $date = explode(" ", date('Y m d H i s', $unixtime));
         $rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $author, $post->post_name);
         foreach ($taxonomies as $taxonomy) {
             $rewritereplace[] = $replace_terms[$taxonomy];
         }
         $permalink = home_url(str_replace($rewritecode, $rewritereplace, $permalink));
         $permalink = user_trailingslashit($permalink, 'single');
     } else {
         // if they're not using the fancy permalink option
         $permalink = home_url('?post_type=' . $post->post_type . '&p=' . $post->ID);
     }
     return $permalink;
 }
Example #4
0
 function get_term_parents($id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array())
 {
     $chain = '';
     $parent = get_term($id, $taxonomy);
     if (is_wp_error($parent)) {
         return $parent;
     }
     if ($nicename) {
         $name = $parent->slug;
     } else {
         $name = $parent->name;
     }
     if ($parent->parent && $parent->parent != $parent->term_id && !in_array($parent->parent, $visited)) {
         $visited[] = $parent->parent;
         $chain .= get_term_parents($parent->parent, $taxonomy, $link, $separator, $nicename, $visited);
     }
     if ($link) {
         $chain .= '<a href="' . get_term_link($parent->slug, $taxonomy) . '" title="' . esc_attr(sprintf(__('View all posts in %s', 'ishyoboy'), $parent->name)) . '">' . $name . '</a>' . $separator;
     } else {
         $chain .= $name . $separator;
     }
     return $chain;
 }
Example #5
0
 function ishyoboy_shortcode_breadcrumbs($atts, $content = null)
 {
     global $ish_options, $ish_woo_id;
     $sc_atts = shortcode_atts(array('id' => '', 'css_class' => '', 'style' => '', 'tooltip' => '', 'tooltip_color' => '', 'color' => '', 'align' => ''), $atts);
     $return = '';
     $return .= '<div class="list-breadcrumbs';
     $return .= '' != $sc_atts['css_class'] ? ' ' . esc_attr($sc_atts['css_class']) : '';
     $return .= '' != $sc_atts['color'] ? ' ' . esc_attr($sc_atts['color']) : '';
     $return .= 'center' == $sc_atts['align'] ? ' acenter' : '';
     $return .= 'right' == $sc_atts['align'] ? ' aright' : '';
     $return .= 'left' == $sc_atts['align'] ? ' aleft' : '';
     $return .= '' != $sc_atts['tooltip'] && '' != $sc_atts['tooltip_color'] ? ' tooltip-' . esc_attr($sc_atts['tooltip_color']) : '';
     $return .= '"';
     $return .= '' != $sc_atts['id'] ? ' id="' . esc_attr($sc_atts['id']) . '"' : '';
     $return .= '' != $sc_atts['style'] ? ' style="' . esc_attr($sc_atts['style']) . '"' : '';
     $return .= '' != $sc_atts['tooltip'] ? ' data-type="tooltip" title="' . esc_attr($sc_atts['tooltip']) . '"' : '';
     $return .= '>' . "\n";
     if (!is_front_page()) {
         if (function_exists('is_woocommerce')) {
             if (!is_woocommerce() && !is_woocommerce_page()) {
                 //$return .= '<p class="breadcrumb"><span class="breadcrumb_info">You are here:</span> <a href="';
                 $return .= '<p class="breadcrumb"><a href="';
                 $return .= home_url();
                 $return .= '">';
                 $return .= __('Home', 'ishyoboy');
                 $return .= "</a> &gt; ";
             }
         } else {
             //$return .= '<p class="breadcrumb"><span class="breadcrumb_info">You are here:</span> <a href="';
             $return .= '<p class="breadcrumb"><a href="';
             $return .= home_url();
             $return .= '">';
             $return .= __('Home', 'ishyoboy');
             $return .= "</a> &gt; ";
         }
     }
     if ((is_category() || is_single()) && (!function_exists('is_woocommerce_page') || !is_woocommerce() && !is_woocommerce_page())) {
         $post_id = get_the_ID();
         $post_type = get_post_type();
         switch ($post_type) {
             case 'portfolio-post':
                 $terms = get_the_terms($post_id, 'portfolio-category');
                 $term = array_pop($terms);
                 if (isset($ish_options['page_for_custom_post_type_portfolio-post']) && '-1' != $ish_options['page_for_custom_post_type_portfolio-post']) {
                     $portfolio_page = get_page($ish_options['page_for_custom_post_type_portfolio-post']);
                     $separator = " &gt; ";
                     $return .= '<a href="' . get_page_link($ish_options['page_for_custom_post_type_portfolio-post']) . '" title="' . esc_attr(sprintf(__("View all posts in %s", 'ishyoboy'), $portfolio_page->post_title)) . '">' . $portfolio_page->post_title . '</a>' . $separator;
                 }
                 $return .= get_term_parents($term->term_id, 'portfolio-category', TRUE, ' &gt; ', FALSE);
                 break;
             default:
                 $category = get_the_category();
                 if (!empty($category)) {
                     $ID = $category[0]->cat_ID;
                     $return .= get_category_parents($ID, TRUE, ' &gt; ', FALSE);
                 }
         }
     } else {
         if (function_exists('is_woocommerce_page') && (is_woocommerce() || is_woocommerce_page())) {
             ob_start();
             woocommerce_breadcrumb(array('delimiter' => ' &gt; ', 'wrap_before' => '<p class="breadcrumb">', 'wrap_after' => '</p>', 'before' => '', 'after' => '', 'home' => _x('Home', 'breadcrumb', 'woocommerce')));
             $return .= ob_get_contents();
             ob_end_clean();
             ob_end_flush();
         } else {
             if (is_tax()) {
                 if (is_tax('portfolio-category')) {
                     $current_term = get_queried_object();
                     if (!empty($current_term)) {
                         //var_dump($current_term);
                         if (isset($ish_options['page_for_custom_post_type_portfolio-post']) && '-1' != $ish_options['page_for_custom_post_type_portfolio-post']) {
                             $portfolio_page = get_page($ish_options['page_for_custom_post_type_portfolio-post']);
                             $separator = " &gt; ";
                             $return .= '<a href="' . get_page_link($ish_options['page_for_custom_post_type_portfolio-post']) . '" title="' . esc_attr(sprintf(__("View all posts in %s", 'ishyoboy'), $portfolio_page->post_title)) . '">' . $portfolio_page->post_title . '</a>' . $separator;
                         }
                         if ($current_term->parent != 0) {
                             $return .= get_term_parents($current_term->parent, 'portfolio-category', TRUE, ' &gt; ', FALSE);
                         }
                         $return .= $current_term->name;
                     }
                 }
             } else {
                 if (is_page()) {
                     global $post;
                     if ($post->post_parent != 0) {
                         $return .= get_page_parents($post->post_parent, TRUE, ' &gt; ', FALSE);
                     }
                 }
             }
         }
     }
     if (!function_exists('is_woocommerce_page') || !is_woocommerce_page()) {
         if (is_single() || is_page()) {
             $return .= get_the_title();
         }
         if (is_tag()) {
             $return .= "Tag: " . single_tag_title('', FALSE);
         }
         if (is_404()) {
             $return .= "404 - Page not Found";
         }
         if (is_search()) {
             $return .= "Search";
         }
         if (is_year()) {
             $return .= get_the_time('Y');
         }
     }
     $return .= '</div>';
     return $return;
 }
Example #6
0
function theme_breadcrumbs()
{
    $delimiter = '&raquo;';
    $name = __('Home', TEMPLATENAME);
    $currentBefore = '<span class="current">';
    $currentAfter = '</span>';
    if (!is_home() && !is_front_page() || is_paged()) {
        echo '<div id="breadcrumbs">';
        global $post;
        $home = home_url();
        echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . '&nbsp;';
        if (is_category()) {
            global $wp_query;
            $cat_obj = $wp_query->get_queried_object();
            $thisCat = $cat_obj->term_id;
            $thisCat = get_category($thisCat);
            $parentCat = get_category($thisCat->parent);
            if ($thisCat->parent != 0) {
                echo get_category_parents($parentCat, TRUE, '&nbsp;' . $delimiter . '&nbsp;');
            }
            echo $currentBefore . __('Archive by category:', TEMPLATENAME) . '&nbsp;&#39;';
            single_cat_title();
            echo '&#39;' . $currentAfter;
        } elseif (is_day()) {
            echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . '&nbsp;';
            echo '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . '&nbsp;';
            echo $currentBefore . get_the_time('d') . $currentAfter;
        } elseif (is_month()) {
            echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . '&nbsp;';
            echo $currentBefore . get_the_time('F') . $currentAfter;
        } elseif (is_year()) {
            echo $currentBefore . get_the_time('Y') . $currentAfter;
        } elseif (is_tax()) {
            $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
            if ($term->parent != 0) {
                $parent =& get_term((int) $term->parent, $term->taxonomy);
                echo get_term_parents($parent, '&nbsp;' . $delimiter . '&nbsp;');
            }
            echo $currentBefore . __('Posts classified under:', TEMPLATENAME) . '&nbsp;&#39;';
            echo $term->name;
            echo '&#39;' . $currentAfter;
        } elseif ($post_type = is_custom_post()) {
            if (is_single()) {
                echo '<a href="' . home_url($post_type->rewrite['slug']) . '">' . $post_type->label . '</a>' . $delimiter . '&nbsp;';
                $tax_names = get_post_taxonomies($post->ID);
                foreach ($tax_names as $tax_name) {
                    $tax = get_taxonomy($tax_name);
                    if ($tax->hierarchical) {
                        break;
                    }
                }
                $cat = get_the_terms(null, $tax_name);
                $cat = reset($cat);
                echo get_term_parents($cat, '&nbsp;' . $delimiter . '&nbsp;');
                echo $currentBefore;
                the_title();
                echo $currentAfter;
            } else {
                echo $currentBefore;
                echo $post_type->label;
                echo $currentAfter;
            }
        } elseif (is_single() && !is_attachment()) {
            $cat = get_the_category();
            $cat = $cat[0];
            echo get_category_parents($cat, TRUE, '&nbsp;' . $delimiter . '&nbsp;');
            echo $currentBefore;
            the_title();
            echo $currentAfter;
        } elseif (is_attachment()) {
            $parent = get_post($post->post_parent);
            $cat = get_the_category($parent->ID);
            $cat = $cat[0];
            echo get_category_parents($cat, TRUE, '&nbsp;' . $delimiter . '&nbsp;');
            echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . '&nbsp;';
            echo $currentBefore;
            the_title();
            echo $currentAfter;
        } elseif (is_page() && !$post->post_parent) {
            echo $currentBefore;
            the_title();
            echo $currentAfter;
        } elseif (is_page() && $post->post_parent) {
            $parent_id = $post->post_parent;
            $breadcrumbs = array();
            while ($parent_id) {
                $page = get_page($parent_id);
                $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
                $parent_id = $page->post_parent;
            }
            $breadcrumbs = array_reverse($breadcrumbs);
            foreach ($breadcrumbs as $crumb) {
                echo $crumb . '&nbsp;' . $delimiter . '&nbsp;';
            }
            echo $currentBefore;
            the_title();
            echo $currentAfter;
        } elseif (is_search()) {
            echo $currentBefore . __('Search results for:', TEMPLATENAME) . '&nbsp;&#39;' . get_search_query() . ' &#39;' . $currentAfter;
        } elseif (is_tag()) {
            echo $currentBefore . __('Posts tagged:', TEMPLATENAME) . '&nbsp;&#39;';
            single_tag_title();
            echo '&#39;' . $currentAfter;
        } elseif (is_author()) {
            global $author;
            $userdata = get_userdata($author);
            echo $currentBefore . __('Articles posted by:', TEMPLATENAME) . '&nbsp;' . $userdata->display_name . $currentAfter;
        } elseif (is_404()) {
            echo $currentBefore . __('Error 404', TEMPLATENAME) . $currentAfter;
        }
        if (get_query_var('paged')) {
            if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) {
                echo ' (';
            }
            echo __('Page') . '&nbsp;' . get_query_var('paged');
            if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) {
                echo ')';
            }
        }
        echo '</div>';
    }
}