Exemplo n.º 1
0
function breadcrumb($args = array())
{
    // Args
    $defaults = apply_filters('breadcrumb_defaults', array('container' => 'div', 'container_class' => 'breadcrumb-container', 'container_id' => '', 'breadcrumb_class' => 'breadcrumb', 'breadcrumb_id' => 'breadcrumb', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<nav id="%1$s" class="%2$s">%3$s</nav>', 'separator' => ' » ', 'echo' => true));
    $args = wp_parse_args($args, $defaults);
    $args = apply_filters('breadcrumb_args', $args);
    $args = (object) $args;
    // Current item
    if (is_404()) {
        $current = new Breadcrumb_Item_404();
    } elseif (is_search()) {
        $current = new Breadcrumb_Item_Search();
    } elseif (is_tax() || is_category() || is_tag()) {
        $current = new Breadcrumb_Item_Taxonomy();
    } elseif (is_archive() || is_home() || is_front_page()) {
        $current = new Breadcrumb_Item_Archive();
    } elseif (is_singular()) {
        $current = new Breadcrumb_Item_Singular();
    } else {
        $current = null;
    }
    $current = apply_filters('breadcrumb_current_item', $current, $args);
    if (!$current) {
        return;
    }
    // Items
    $breadcrumb_items = array_merge($current->parents(), array($current), $current->children());
    $breadcrumb_items = apply_filters('breadcrumb_objects', $breadcrumb_items, $args);
    // Pre-output
    $breadcrumb = $items = '';
    $show_container = false;
    if ($args->container) {
        $allowed_tags = apply_filters('breadcrumb_container_allowedtags', array('div', 'nav'));
        if (in_array($args->container, $allowed_tags)) {
            $show_container = true;
            $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : '';
            $id = $args->container_id ? ' id="' . esc_attr($args->container_id) . '"' : '';
            $breadcrumb .= '<' . $args->container . $id . $class . '>';
        }
    }
    $items .= breadcrumb_items($breadcrumb_items, $args);
    unset($breadcrumb_items);
    $wrap_id = $args->breadcrumb_id ? $args->breadcrumb_id : '';
    $wrap_class = $args->breadcrumb_class ? $args->breadcrumb_class : '';
    $items = apply_filters('breadcrumb_items', $items, $args);
    // Output
    $breadcrumb .= sprintf($args->items_wrap, esc_attr($wrap_id), esc_attr($wrap_class), $items);
    unset($items);
    if ($show_container) {
        $breadcrumb .= '</' . $args->container . '>';
    }
    $breadcrumb = apply_filters('breadcrumb', $breadcrumb, $args);
    if ($args->echo) {
        echo $breadcrumb;
    } else {
        return $breadcrumb;
    }
}
Exemplo n.º 2
0
function breadcrumb_items($db, $id_col, $cat_col, $name_col, $id)
{
    global $aidlink;
    $result = dbquery("SELECT {$id_col}, {$cat_col}, {$name_col} FROM {$db} WHERE {$id_col}='{$id}' LIMIT 1");
    if (dbrows($result) > 0) {
        $data = dbarray($result);
        if ($data[$cat_col] > 0) {
            echo breadcrumb_items($db, $id_col, $cat_col, $name_col, $data[$cat_col]);
            echo "<li><a class='section' href='" . FUSION_SELF . $aidlink . "&amp;cid=" . $data[$id_col] . "'>" . $data[$name_col] . "</a></li>\n";
        } else {
            echo "<li><a class='section' href='" . FUSION_SELF . $aidlink . "&amp;cid=" . $data[$id_col] . "'>" . $data[$name_col] . "</a></li>\n";
        }
    }
}