/** * Render the category breadcrumb. * * @access public * @since 8.5.18 * @static * * @param array $atts The attributes array. { * * @type bool $link Whether to format as link or as a string. * Default: FALSE * @type string $separator How to separate categories. * Default: '/' * @type bool $force_home Default: FALSE * @type int $home_id Default: The page set as the directory home page. * @type bool $return Whether or not to return or echo the pagination control. Set to TRUE to return instead of echo. * Default: FALSE * } * * @return string A list of category parents on success. */ public static function categoryBreadcrumb($atts) { $defaults = array('link' => FALSE, 'separator' => '/', 'force_home' => FALSE, 'home_id' => cnSettingsAPI::get('connections', 'connections_home_page', 'page_id'), 'return' => FALSE); $atts = cnSanitize::args($atts, $defaults); $html = ''; if ($current = cnCategory::getCurrent()) { $home = cnURL::permalink(array('type' => 'home', 'title' => esc_html__('Home', 'connections'), 'text' => esc_html__('Home', 'connections'), 'force_home' => $atts['force_home'], 'home_id' => $atts['home_id'], 'return' => TRUE)); $breadcrumb = cnTemplatePart::getCategoryParents($current->parent, array('link' => $atts['link'], 'separator' => $atts['separator'], 'force_home' => $atts['force_home'], 'home_id' => $atts['home_id'])); if (is_wp_error($breadcrumb)) { $breadcrumb = ''; } //$currentLink = '<a href="' . esc_url( cnTerm::permalink( $current, 'category', $atts ) ) . '">' . $current->name . '</a>'; $html = $home . $atts['separator'] . $breadcrumb . esc_html($current->name); $html = '<div class="cn-category-breadcrumb">' . $html . '</div>'; } return self::echoOrReturn($atts['return'], $html); }
/** * Displays the category list in a HTML list or custom format. * * NOTE: This is the Connections equivalent of @see get_the_category_list() in WordPress core ../wp-includes/category-template.php * * @access public * @since unknown * * @param array $atts { * Optional. An array of arguments. * * @type string $container_tag The HTML tag to be used for the container element. * Default: div * @type string $label_tag The HTML tag to be used for the category label element. * Default: span * @type string $item_tag The HTML tag to be used for the category element. * Default: span * @type string $type The display type to be used to display the categories. * Accepts: block|list * Default: block * @type string $list If the $type is list, which type? * Accepts: ordered|unordered * Default: unordered * @type string $label The label to be displayed before the categories. * Default: Categories: * @type string $separator The category separator used when separating categories when $type == list * Default: ', ' * @type string $parent_separator The separator to be used when displaying the category's hierarchy. * Default: ' » ' * @type string $before String content to display before the categories. * @type string $after String content to display after the categories. * @type bool $link Whether or not render the categories as permalinks. * Default: false * @type bool $parents Whether or not to display the category hierarchy. * Default: false * @type bool $return Whether or not to echo or return the HTML. * Default: false * } * * @return string */ public function getCategoryBlock($atts = array()) { global $wp_rewrite; $defaults = array('container_tag' => 'div', 'label_tag' => 'span', 'item_tag' => 'span', 'type' => 'block', 'list' => 'unordered', 'label' => __('Categories:', 'connections') . ' ', 'separator' => ', ', 'parent_separator' => ' » ', 'before' => '', 'after' => '', 'link' => FALSE, 'parents' => FALSE, 'return' => FALSE); /** * All extensions to filter the method default and supplied args. * * @since 8.5.18 */ $atts = cnSanitize::args(apply_filters('cn_output_atts_category', $atts), apply_filters('cn_output_default_atts_category', $defaults)); $categories = $this->getCategory(); $count = count($categories); $html = ''; $label = ''; $items = array(); if (empty($categories)) { return $html; } if ('list' == $atts['type']) { $atts['item_tag'] = 'li'; } if (0 < strlen($atts['label'])) { $label = sprintf('<%1$s class="cn_category_label">%2$s</%1$s> ', $atts['label_tag'], esc_html($atts['label'])); } $i = 1; foreach ($categories as $category) { $text = ''; if ($atts['parents']) { // If the term is a root parent, skip. if (0 !== $category->parent) { $text .= cnTemplatePart::getCategoryParents($category->parent, array('link' => $atts['link'], 'separator' => $atts['parent_separator'], 'force_home' => $this->directoryHome['force_home'], 'home_id' => $this->directoryHome['page_id'])); } } if ($atts['link']) { $rel = is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ? 'rel="category tag"' : 'rel="category"'; $url = cnTerm::permalink($category, 'category', array('force_home' => $this->directoryHome['force_home'], 'home_id' => $this->directoryHome['page_id'])); $text .= '<a href="' . $url . '" ' . $rel . '>' . esc_html($category->name) . '</a>'; } else { $text .= esc_html($category->name); } $items[] = apply_filters('cn_entry_output_category_item', sprintf('<%1$s class="cn-category-name cn_category cn-category-%2$d">%3$s%4$s</%1$s>', $atts['item_tag'], $category->term_id, $text, $count > $i && 'list' !== $atts['type'] ? esc_html($atts['separator']) : ''), $category, $count, $i, $atts, $this); $i++; // Increment here so the correct value is passed to the filter. } /* * Remove NULL, FALSE and empty strings (""), but leave values of 0 (zero). * Filter our these in case someone hooks into the `cn_entry_output_category_item` filter and removes a category * by returning an empty value. */ $items = array_filter($items, 'strlen'); if ('list' == $atts['type']) { $html .= sprintf('<%1$s class="cn-category-list">%2$s</%1$s>', 'unordered' === $atts['list'] ? 'ul' : 'ol', implode('', $items)); } else { $html .= implode('', $items); } $html = apply_filters('cn_entry_output_category_container', sprintf('<%1$s class="cn-categories">%2$s</%1$s>' . PHP_EOL, $atts['container_tag'], $atts['before'] . $label . $html . $atts['after']), $atts); return $this->echoOrReturn($atts['return'], $html); }