Example #1
0
 function get_page_parents($id, $link = false, $separator = '/', $nicename = false, $visited = array())
 {
     $chain = '';
     $parent =& get_page($id);
     if (is_wp_error($parent)) {
         return $parent;
     }
     if ($nicename) {
         $name = $parent->post_slug;
     } else {
         $name = apply_filters('the_title', $parent->post_title);
     }
     if ($parent->post_parent && $parent->post_parent != $parent->ID && !in_array($parent->post_parent, $visited)) {
         $visited[] = $parent->post_parent;
         $chain .= get_page_parents($parent->post_parent, $link, $separator, $nicename, $visited);
     }
     if ($link) {
         $chain .= '<a href="' . get_page_link($id) . '">' . $name . '</a>' . $separator;
     } else {
         $chain .= $name . $separator;
     }
     return $chain;
 }
Example #2
0
/**
 * Generates page menu. Only for internal use. For themes, use theme_menu().
 *
 * @since 4.7
 * @package site
 */
function theme_menu_data($block, $inline, $active_id, $level, $dir)
{
    //If specified directory does not exist, just return.
    if (!is_dir($dir)) {
        return;
    }
    $files = read_dir_contents($dir, 'files');
    if ($files) {
        //Sort the array.
        natcasesort($files);
        echo '<' . $block . '>';
        foreach ($files as $file) {
            include $dir . '/' . $file;
            $file = get_page_seoname($dir . '/' . $file);
            //Only display in menu if page isn't hidden by user.
            if (isset($hidden) && $hidden == 'no') {
                //Get parents of the currently displayed page
                $parents = get_page_parents(CURRENT_PAGE_SEONAME);
                //Strip parents from $file, but only if it's a sub page
                if (strpos($file, '/') !== false && file_exists(PAGE_DIR . '/' . get_page_filename($file))) {
                    $file_levels = preg_split('|\\/|', $file);
                    $file_stripped = $file_levels[count($file_levels) - 1];
                } else {
                    $file_stripped = $file;
                }
                //Show an active inline for current page...
                if ($active_id && CURRENT_PAGE_SEONAME == $file) {
                    echo '<' . $inline . ' class="' . $active_id . '" id="' . $active_id . '">';
                } elseif ($active_id && $parents && array_search($file_stripped, $parents) !== false) {
                    echo '<' . $inline . ' class="' . $active_id . '">';
                } else {
                    echo '<' . $inline . '>';
                }
                //Unset parents array
                unset($parents);
                //Display link
                echo '<a href="' . SITE_URL . '/' . PAGE_URL_PREFIX . $file . '" >' . $title . '</a>';
                preg_match_all('|\\/|', $file, $page_level);
                $page_level = count($page_level[0]);
                if ($level > $page_level && is_dir(PAGE_DIR . '/' . $file)) {
                    theme_menu_data($block, $inline, $active_id, $level, PAGE_DIR . '/' . $file);
                }
                echo '</' . $inline . '>';
            }
        }
        unset($file);
        echo '</' . $block . '>';
    }
}
Example #3
0
 function get_page_parents($id, $link = false, $separator = '/', $nicename = false, $visited = array())
 {
     $chain = '';
     $parent = get_post($id);
     if (is_wp_error($parent)) {
         return $parent;
     }
     if ($nicename) {
         $name = $parent->post_name;
     } else {
         $name = $parent->post_title;
     }
     if ($parent->post_parent && !in_array($parent->post_parent, $visited)) {
         $visited[] = $parent->post_parent;
         $chain .= get_page_parents($parent->post_parent, $link, $separator, $nicename, $visited);
     }
     if ($link) {
         $chain .= '<a href="' . get_page_link($parent->ID) . '" title="' . esc_attr(sprintf(__('View %s page', 'ishyoboy'), $parent->post_title)) . '">' . $name . '</a>' . $separator;
     } else {
         $chain .= $name . $separator;
     }
     return $chain;
 }
Example #4
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;
 }