Astra_Breadcrumb_Trail::add_term_archive_items()
Adds the items to the trail items array for taxonomy term archives.
Description
Return
(void)
Source
File: inc/addons/breadcrumbs/class-astra-breadcrumb-trail.php
protected function add_term_archive_items() { global $wp_rewrite; // Get some taxonomy and term variables. $term = get_queried_object(); $taxonomy = get_taxonomy( $term->taxonomy ); $done_post_type = false; // If there are rewrite rules for the taxonomy. if ( false !== $taxonomy->rewrite ) { // If 'with_front' is true, dd $wp_rewrite->front to the trail. if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front ) { $this->add_rewrite_front_items(); } // Get parent pages by path if they exist. $this->add_path_parents( $taxonomy->rewrite['slug'] ); // Add post type archive if its 'has_archive' matches the taxonomy rewrite 'slug'. if ( $taxonomy->rewrite['slug'] ) { $slug = trim( $taxonomy->rewrite['slug'], '/' ); // Deals with the situation if the slug has a '/' between multiple // strings. For example, "movies/genres" where "movies" is the post // type archive. $matches = explode( '/', $slug ); // If matches are found for the path. if ( isset( $matches ) ) { // Reverse the array of matches to search for posts in the proper order. $matches = array_reverse( $matches ); // Loop through each of the path matches. foreach ( $matches as $match ) { // Get public post types that match the rewrite slug. $post_types = $this->get_post_types_by_slug( $match ); if ( ! empty( $post_types ) ) { $post_type_object = $post_types[0]; // Add support for a non-standard label of 'archive_title' (special use case). $label = ! empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name; // Core filter hook. $label = apply_filters( 'post_type_archive_title', $label, $post_type_object->name ); // Add the post type archive link to the trail. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $post_type_object->name ) ), $label ); $done_post_type = true; // Break out of the loop. break; } } } } } // If there's a single post type for the taxonomy, use it. if ( false === $done_post_type && 1 === count( $taxonomy->object_type ) && post_type_exists( $taxonomy->object_type[0] ) ) { // If the post type is 'post'. if ( 'post' === $taxonomy->object_type[0] ) { $post_id = get_option( 'page_for_posts' ); if ( 'posts' !== get_option( 'show_on_front' ) && 0 < $post_id ) { $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), get_the_title( $post_id ) ); } // If the post type is not 'post'. } else { $post_type_object = get_post_type_object( $taxonomy->object_type[0] ); $label = ! empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name; // Core filter hook. $label = apply_filters( 'post_type_archive_title', $label, $post_type_object->name ); $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $post_type_object->name ) ), $label ); } } // If the taxonomy is hierarchical, list its parent terms. if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent ) { $this->add_term_parents( $term->parent, $term->taxonomy ); } // Add the term name to the trail end. if ( is_paged() ){ $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $term->taxonomy ) ), single_term_title( '', false ) ); } elseif ( true === $this->args['show_title'] ) { $this->items[] = single_term_title( '', false ); } }
Expand full source code Collapse full source code View on Trac
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |