/** * Manages CSS relationship classes applied to Shopp elements appearing in a WordPress navigation menu * * @author Jonathan Davis * @since 1.2 * * @param array $menuitems The provided WordPress menu items * @return array Updated menu items with proper relationship classes **/ public function menus($menuitems) { $is_shopp_page = is_shopp_page(); $keymap = array(); $parents = array(); foreach ($menuitems as $key => $item) { $page = false; // Remove the faulty wp_page_menu (deprecated) class for Shopp pages if ($is_shopp_page && in_array('current_page_parent', $item->classes)) { unset($item->classes[array_search('current_page_parent', $item->classes)]); } // Otherwise, skip dealing with any non-Shopp page if (ShoppPages::QUERYVAR == $item->type) { // Determine the queried Shopp page object name $Page = ShoppPages()->requested(); if ($Page && !is_shopp_collection()) { $page = $Page->name(); } // Set the catalog as current page parent if ('catalog' == $item->object && ($is_shopp_page || is_shopp_product())) { $item->classes[] = 'current-page-parent'; } $keymap[$item->db_id] = $key; } if ('shopp_collection' == $item->type) { $page = get_query_var($item->type); $keymap[$item->db_id] = $key; } if ($page == $item->object) { $item->classes[] = 'current-page-item'; $item->classes[] = 'current-menu-item'; $parents[] = $item->menu_item_parent; } } foreach ((array) $parents as $parentid) { if (!isset($keymap[$parentid])) { continue; } $parent = $menuitems[$keymap[$parentid]]; $parent->classes[] = 'current-menu-parent'; $parent->classes[] = 'current-page-parent'; $parent->classes[] = 'current-menu-ancestor'; $parent->classes[] = 'current-page-ancestor'; $ancestor = $parent; while (0 != $ancestor->menu_item_parent) { $ancestor = $menuitems[$keymap[$ancestor->menu_item_parent]]; $ancestor->classes[] = 'current-menu-ancestor'; $ancestor->classes[] = 'current-page-ancestor'; } } return $menuitems; }
public function content($content) { global $wp_query; // Only modify content for Shopp collections (Shopp smart collections and taxonomies) if (!$wp_query->is_main_query() || !is_shopp_collection()) { return $content; } remove_filter('the_content', array($this, 'content'), 20); $Collection = ShoppCollection(); ob_start(); if (empty($Collection)) { locate_shopp_template(array('catalog.php'), true); } else { $templates = array('category.php', 'collection.php'); $ids = array('slug', 'id'); foreach ($ids as $property) { if (isset($Collection->{$property})) { $id = $Collection->{$property}; } array_unshift($templates, 'category-' . $id . '.php', 'collection-' . $id . '.php'); } locate_shopp_template($templates, true); } $content = ob_get_clean(); return apply_filters('shopp_category_template', $content); }
/** * Determines if the requested page is a Shopp page or if it matches a given Shopp page * * Also checks to see if the current loaded query is a Shopp product or product taxonomy. * * @api * @since 1.0 * * @param string $page (optional) System page name ID for the correct ShoppStorefront page {@see ShoppPages class} * @param WP_Query $wp_query (optional) will use the global wp_query by default if false, or the provided WP_Query object * @return boolean **/ function is_shopp_page($page = false, $wp_query = false) { if (false === $wp_query) { global $wp_the_query; $wp_query = $wp_the_query; } if (empty($wp_query->query_vars)) { shopp_debug('Conditional is_shopp_page functions do not work before the WordPress query is run. Before then, they always return false.'); } $is_shopp_page = false; $Page = ShoppPages()->requested(); if (false === $page) { // Check if the current request is a shopp page request // Product and collection pages are considered a Shopp page request if (is_shopp_product($wp_query) || $wp_query->get('post_type') == ShoppProduct::$posttype) { $is_shopp_page = true; } if (is_shopp_collection($wp_query)) { $is_shopp_page = true; } if (false !== $Page) { $is_shopp_page = true; } } elseif (false !== $Page) { // Check if the given shopp page name is the current request if ($Page->name() == $page) { $is_shopp_page = true; } } return $is_shopp_page; }
/** * Checks if the current page is a collection page * * @api `shopp('storefront.is-collection')` * @since 1.1 * * @param string $result The output * @param array $options The options * @param ShoppStorefront $O The working object * @return bool True if it is the collection page, false otherwise **/ public static function is_collection($result, $options, $O) { return is_shopp_collection(); }