function permapath($path, $echo = true)
{
    $permalink = get_permalink(get_page_id_by_path($path));
    if ($echo) {
        echo $permalink;
    }
    return $permalink;
}
function cc_breadcrumbs($before = '<div class="breadcrumbs">', $glue = ' / ', $after = '</div>')
{
    global $post;
    $stack = array();
    $page_for_posts = get_option('page_for_posts', 0);
    array_push($stack, array('title' => 'cubetech', 'link' => get_option('home')));
    if (is_page()) {
        $page_id = $post->ID;
        $page_obj = get_page($page_id);
        $tmp = array();
        do {
            $tmp[] = array('title' => apply_filters('the_title', $page_obj->post_title), 'link' => get_permalink($page_obj->ID));
        } while ($page_obj->post_parent != 0 && ($page_obj = get_page($page_obj->post_parent)));
        $tmp = array_reverse($tmp);
        foreach ($tmp as $breadcrumb_elem) {
            array_push($stack, $breadcrumb_elem);
        }
    } else {
        if ($page_for_posts) {
            $blog_page = get_page($page_for_posts);
            if (get_post_type() == 'post') {
                array_push($stack, array('title' => apply_filters('the_title', $blog_page->post_title), 'link' => get_permalink($blog_page->ID)));
            }
        }
        if (is_archive()) {
            array_push($stack, array('title' => 'Archive', 'link' => get_permalink(get_page_id_by_path('archive'))));
        }
        if (get_post_type() == 'portfolio') {
            $page = get_page_by_path('portfolio');
            array_push($stack, array('title' => get_the_title($page->ID), 'link' => get_permalink($page->ID)));
            array_push($stack, array('title' => get_the_title(), 'link' => get_permalink()));
        } else {
            if (is_single()) {
                if ($post->post_type == 'post') {
                    array_push($stack, array('title' => get_the_title(), 'link' => get_permalink()));
                }
            } else {
                if (is_category()) {
                    $category = get_query_var('cat');
                    $ancestors = array_reverse(cc_category_parents($category));
                    foreach ($ancestors as $breadcrumb_elem) {
                        array_push($stack, $breadcrumb_elem);
                    }
                } else {
                    if (is_tag()) {
                        array_push($stack, array('title' => single_tag_title('', false), 'link' => get_tag_link(get_query_var('tag'))));
                    } else {
                        if (is_day()) {
                            array_push($stack, array('title' => get_the_time('F j, Y'), 'link' => get_day_link(get_the_time('j'), get_the_time('F'), get_the_time('Y'))));
                        } else {
                            if (is_month()) {
                                array_push($stack, array('title' => get_the_time('F Y'), 'link' => get_month_link(get_the_time('F'), get_the_time('Y'))));
                            } else {
                                if (is_year()) {
                                    array_push($stack, array('title' => get_the_time('Y'), 'link' => get_year_link(get_the_time('Y'))));
                                } else {
                                    if (is_search()) {
                                        array_push($stack, array('title' => 'Suchresultate', 'link' => '#'));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($page_for_posts && count($stack) < 2 || count($stack) < 1) {
        return;
    }
    $elems = array();
    $i = 0;
    foreach ($stack as $elem) {
        if ($i == count($stack) - 1) {
            //$html = '<a href="' . $elem['link'] . '" class="active">' . $elem['title'] . '</a>';
            $html = '<span>' . $elem['title'] . '</span>';
        } else {
            $html = '<a href="' . $elem['link'] . '">' . $elem['title'] . '</a>';
        }
        $elems[] = $html;
        $i++;
    }
    echo $before . implode($glue, $elems) . $after;
}