Ejemplo n.º 1
0
    /**
     * get_crumb
     * 
     * 
     * @return string The html code
     * @version 2.0.7
     * 
     */
    public static function get_crumb(array $args = [])
    {
        $args = array_merge(['header' => null, 'footer' => null], $args);
        $links = [];
        if (theme_cache::is_home()) {
            return null;
        }
        $links['home'] = '<a href="' . theme_cache::home_url() . '" class="home" title="' . ___('Back to Homepage') . '">
			<i class="fa fa-home fa-fw"></i>
			<span class="tx">' . ___('Back to Homepage') . '</span>
		</a>';
        $split = '<span class="split"><i class="fa fa-angle-right"></i></span>';
        /* category */
        if (theme_cache::is_category()) {
            $cat_curr = theme_features::get_current_cat_id();
            if ($cat_curr > 1) {
                $links_cat = get_category_parents($cat_curr, true, '%split%');
                $links_cats = explode('%split%', $links_cat);
                array_pop($links_cats);
                $links['category'] = implode($split, $links_cats);
                $links['curr_text'] = ___('Category Browser');
            }
            /* tag */
        } else {
            if (theme_cache::is_tag()) {
                $tag_id = theme_features::get_current_tag_id();
                $tag_obj = get_tag($tag_id);
                $links['tag'] = '<a href="' . esc_url(get_tag_link($tag_id)) . '">' . esc_html(theme_features::get_current_tag_name()) . '</a>';
                $links['curr_text'] = ___('Tags Browser');
                /* date */
            } else {
                if (theme_cache::is_date()) {
                    global $wp_query;
                    $day = $wp_query->query_vars['day'];
                    $month = $wp_query->query_vars['monthnum'];
                    $year = $wp_query->query_vars['year'];
                    /* day */
                    if (theme_cache::is_day()) {
                        $date_link = get_day_link(null, null, $day);
                        /* month */
                    } else {
                        if (theme_cache::is_month()) {
                            $date_link = get_month_link($year, $month);
                            /* year */
                        } else {
                            if (theme_cache::is_year()) {
                                $date_link = get_year_link($year);
                            }
                        }
                    }
                    $links['date'] = '<a href="' . $date_link . '">' . theme_cache::wp_title('', false) . '</a>';
                    $links['curr_text'] = ___('Date Browser');
                    /* search*/
                } else {
                    if (theme_cache::is_search()) {
                        // $nav_link = null;
                        $links['curr_text'] = sprintf(___('Search Result: %s'), esc_html(get_search_query()));
                        /* author */
                    } else {
                        if (theme_cache::is_author()) {
                            global $author;
                            $user = get_user_by('id', $author);
                            $links['author'] = '<a href="' . theme_cache::get_author_posts_url($author) . '">' . theme_cache::get_the_author_meta('display_name', $user->ID) . '</a>';
                            $links['curr_text'] = ___('Author posts');
                            /* archive */
                        } else {
                            if (theme_cache::is_archive()) {
                                $links['archive'] = '<a href="' . get_current_url() . '">' . theme_cache::wp_title('', false) . '</a>';
                                $links['curr_text'] = ___('Archive Browser');
                                /* Singular */
                            } else {
                                if (theme_cache::is_singular()) {
                                    global $post;
                                    /* The page parent */
                                    if ($post->post_parent) {
                                        $links['singular'] = '<a href="' . theme_cache::get_permalink($post->post_parent) . '">' . theme_cache::get_the_title($post->post_parent) . '</a>';
                                    }
                                    /**
                                     * post / page
                                     */
                                    if (theme_features::get_current_cat_id() > 1) {
                                        $categories = get_the_category($post->ID);
                                        foreach ($categories as $key => $row) {
                                            $parent_id[$key] = $row->category_parent;
                                        }
                                        array_multisort($parent_id, SORT_ASC, $categories);
                                        foreach ($categories as $cat) {
                                            $cat_name = esc_html($cat->name);
                                            $links['singular'] = '<a href="' . esc_url(get_category_link($cat->cat_ID)) . '" title="' . sprintf(___('View all posts in %s'), $cat_name) . '">' . $cat_name . '</a>';
                                        }
                                    }
                                    //$links['curr_text'] = esc_html(theme_cache::get_the_title($post->ID));
                                    /* 404 */
                                } else {
                                    if (theme_cache::is_404()) {
                                        // $nav_link = null;
                                        $links['curr_text'] = ___('Not found');
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return '<div class="crumb-container">
		' . $args['header'] . '
		<nav class="crumb">
			' . implode($split, apply_filters('crumb_links', $links)) . '
		</nav>
		' . $args['footer'] . '
	</div>';
    }