/** * Gets breadcrumbs for the current context. * * If you want to add/delete some choices, hook into the g1_breadcrumbs custom filter. * * @return array */ public function get() { global $post; $this->breadcrumbs = array(); $this->breadcrumbs[] = array('href' => home_url('/'), 'text' => __('Home', 'g1_theme')); // Blog Page if (is_home() && !is_front_page()) { $id = intval(g1_get_theme_option('post_type_post', 'page_for_posts')); // WPML fallback if (function_exists('icl_object_id')) { $id = absint(icl_object_id($id, 'page', true)); } if ($id) { $href = get_permalink($id); $text = get_the_title($id); $this->breadcrumbs[] = array('href' => $href, 'text' => $text); } } elseif (is_singular()) { if (!is_page()) { if ('post' == get_post_type()) { $id = intval(g1_get_theme_option('post_type_post', 'page_for_posts')); // WPML fallback if (function_exists('icl_object_id')) { $id = absint(icl_object_id($id, 'page', true)); } if ($id) { $href = get_permalink($id); $text = get_the_title($id); $this->breadcrumbs[] = array('href' => $href, 'text' => $text); } } elseif (!is_attachment()) { $post_type_obj = get_post_type_object(get_post_type()); if ($post_type_obj) { $href = get_post_type_archive_link(get_post_type()); $text = apply_filters('post_type_archive_title', $post_type_obj->labels->name); $this->breadcrumbs[] = array('href' => $href, 'text' => $text); } } } // Add subpages if any if ($post->post_parent) { $parent_id = $post->post_parent; $parent_breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $parent_breadcrumbs[] = array('href' => get_permalink($page->ID), 'text' => get_the_title($page->ID)); $parent_id = $page->post_parent; } $parent_breadcrumbs = array_reverse($parent_breadcrumbs); $this->breadcrumbs = array_merge($this->breadcrumbs, $parent_breadcrumbs); } // Add the current page $this->breadcrumbs[] = array('href' => get_permalink($post->ID), 'text' => get_the_title($post->ID)); } elseif (is_post_type_archive()) { $post_type = get_post_type(); $href = get_post_type_archive_link($post_type); $text = post_type_archive_title('', false); $page_id = G1_Archive_Page_Feature()->get_page_id($post_type); // WPML fallback if (function_exists('icl_object_id')) { $page_id = absint(icl_object_id($page_id, 'page', true)); } if (!empty($page_id)) { $title = get_the_title($page_id); } if (!empty($title)) { $text = $title; } $this->breadcrumbs[] = array('href' => $href, 'text' => $text); } elseif (is_category()) { $category_id = get_query_var('cat'); $category = get_category($category_id); // Temporary array for the current category and parents (if any) $temp = array(); while ($category_id) { $temp[] = array('href' => get_category_link($category_id), 'text' => get_cat_name($category_id)); /* Check for a parent category */ if ($category->category_parent) { $category_id = $category->category_parent; $category = get_category($category_id); } else { $category_id = 0; } } if (count($temp)) { $temp = array_reverse($temp); } /* Merge with temporary array */ $this->breadcrumbs = array_merge($this->breadcrumbs, $temp); } elseif (is_tag()) { $this->add_tag_breadcrumbs(); } elseif (is_tax()) { $this->add_tax_breadcrumbs(); } elseif (is_year()) { $this->add_year_breadcrumbs(); } elseif (is_month()) { $this->add_month_breadcrumbs(); } elseif (is_day()) { $this->add_day_breadcrumbs(); } elseif (is_author()) { $this->add_author_breadcrumbs(); } elseif (is_search()) { $this->add_search_breadcrumbs(); } elseif (is_404()) { $this->add_404_breadcrumbs(); } // Call the functions added to a filter hook $this->breadcrumbs = apply_filters('g1_breadcrumbs', $this->breadcrumbs); $this->remove_duplicates(); return $this->breadcrumbs; }
/** * Get elements of the current context * * @return array */ public function get($id = null) { $elements = array(); if (is_singular()) { $elements = G1_Single_Element_Manager()->get_single_values(); } elseif (is_home() || is_post_type_archive()) { $post_type = get_query_var('post_type'); if (empty($post_type)) { $post_type = 'post'; } $page_id = G1_Archive_Page_Feature()->get_page_id($post_type); // WPML fallback if (function_exists('icl_object_id')) { $page_id = absint(icl_object_id($page_id, 'page', true)); } if ($page_id) { $elements = G1_Single_Element_Manager()->get_single_values($page_id); } else { $elements = G1_Single_Element_Manager()->get_default_values('page'); } $elements['collection'] = G1_Collection_Element_Manager()->get_post_type_archive_values(); } elseif (is_archive()) { $post_type = get_query_var('post_type'); if (empty($post_type)) { $post_type = 'post'; } $elements = G1_Single_Element_Manager()->get_default_values('post'); $elements['collection'] = array(); if (is_date() || is_author()) { $elements['collection'] = G1_Collection_Element_Manager()->get_default_values('post'); } elseif (is_category()) { $taxonomy = 'category'; $term = get_query_var('cat'); if (is_numeric($term)) { $term_obj = get_term_by('id', $term, $taxonomy); } else { $term_obj = get_term_by('slug', $term, $taxonomy); } $elements['sidebar-1'] = $this->get_sidebar($term_obj->term_taxonomy_id, 'category'); if ($term_obj) { $elements['collection'] = G1_Collection_Element_Manager()->get_term_values($term_obj); } else { $elements['collection'] = G1_Collection_Element_Manager()->get_default_values('post'); } } elseif (is_tag()) { $taxonomy = 'post_tag'; $term = get_query_var('tag'); if (is_numeric($term)) { $term_obj = get_term_by('id', $term, $taxonomy); } else { $term_obj = get_term_by('slug', $term, $taxonomy); } $elements['sidebar-1'] = $this->get_sidebar($term_obj->term_taxonomy_id, 'post_tag'); if ($term_obj) { $elements['collection'] = G1_Collection_Element_Manager()->get_term_values($term_obj); } else { $elements['collection'] = G1_Collection_Element_Manager()->get_default_values('post'); } } elseif (is_tax()) { $taxonomy = get_query_var('taxonomy'); $term = get_query_var('term'); $term_obj = get_term_by('slug', $term, $taxonomy); if ($term_obj) { $elements['sidebar-1'] = $this->get_sidebar($term_obj->term_taxonomy_id, $taxonomy); $elements['collection'] = G1_Collection_Element_Manager()->get_term_values($term_obj); } } } // Apply custom filter $elements = apply_filters('g1_get_elements', $elements); // Replace 'none' values with boolean false $elements = $this->replace_none_values($elements); if (null !== $id) { if (array_key_exists($id, $elements)) { return $elements[$id]; } else { return null; } } else { return $elements; } }
} /** * Quasi-singleton for our feature * * @return G1_Archive_Page_Feature */ function G1_Archive_Page_Feature() { static $instance; if (!isset($instance)) { $instance = new G1_Archive_Page_Feature(); } return $instance; } // Fire in the hole :) G1_Archive_Page_Feature(); class G1_Archive_Posts_Per_Page_Feature { public function __construct() { $this->setup_hooks(); $this->global_feature = 'g1-global-archive-posts-per-page'; $this->individual_feature = 'g1-individual-archive-posts-per-page'; } /** * Set up all hooks */ protected function setup_hooks() { add_filter(get_redux_opts_sections_filter_name(), array($this, 'register_global_post_type_setting'), 12); add_filter(get_redux_opts_sections_filter_name(), array($this, 'register_global_taxonomy_setting'), 12);
function g1_render_content_before_collection($collection, $query) { if ($query->is_main_query() && $query->is_post_type_archive()) { $page_id = G1_Archive_Page_Feature()->get_page_id(get_query_var('post_type')); // WPML fallback if (function_exists('icl_object_id')) { $page_id = absint(icl_object_id($page_id, 'page', true)); } if ($page_id) { $page = get_page($page_id); if ($page) { $content = $page->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); if (strlen($content)) { echo '<div class="g1-archive-intro">' . $content . '</div>'; } } } } }