astra_breadcrumb_get_items( array $args )

Gets the items for the RDFa Breadcrumb.


Description


Parameters

$args

(array) (Required) Mixed arguments for the menu.


Source

File: addons/advanced-headers/classes/astra-breadcrumbs.php

	function astra_breadcrumb_get_items( $args ) {
		global $wp_query;
		$item          = array();
		$show_on_front = get_option( 'show_on_front' );
		/* Link to front page. */
		if ( ! is_front_page() ) {
			$item[] = '<span class="ast-breadcrumbs-link-wrap" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a itemprop="item" rel="v:url" property="v:title" href="' . esc_url( home_url( '/' ) ) . '"><span itemprop="name">' . $args['home'] . '</span><meta itemprop="position" content="${content}"/></a></span>';
		}

		/* If woocommerce is installed and we're on a woocommerce page. */
		if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
			woocommerce_breadcrumb();
			return false;
		}
		/* Front page. */
		if ( is_home() && ! ( is_front_page() && is_home() ) ) {
			// Blog page.
			$id           = astra_get_post_id();
			$home_page    = get_page( $wp_query->get_queried_object_id() );
			$item         = array_merge( $item, astra_breadcrumb_get_parents( $home_page->post_parent ) );
			$item['last'] = '<span itemprop="name">' . get_the_title( $id ) . '</span>';
		} elseif ( function_exists( 'is_bbpress' ) && is_bbpress() ) {
			$item = array_merge( $item, astra_breadcrumb_get_bbpress_items() );
			// If viewing a singular post.
		} elseif ( is_singular() ) {
			$post             = $wp_query->get_queried_object();
			$post_id          = (int) $wp_query->get_queried_object_id();
			$post_type        = $post->post_type;
			$post_type_object = get_post_type_object( $post_type );
			if ( 'post' === $post_type && $args['show_blog'] ) {
				$item[] = '<span class="ast-breadcrumbs-link-wrap" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a itemprop="item" rel="v:url" property="v:title" href="' . get_permalink( get_option( 'page_for_posts' ) ) . '"><span itemprop="name">' . get_the_title( get_option( 'page_for_posts' ) ) . '</span></a></span>';
			}
			if ( 'page' !== $post_type ) {
				/* If there's an archive page, add it. */
				if ( function_exists( 'get_post_type_archive_link' ) && ! empty( $post_type_object->has_archive ) ) {
					$item[] = '<span class="ast-breadcrumbs-link-wrap" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a itemprop="item" rel="v:url" property="v:title" href="' . get_post_type_archive_link( $post_type ) . '" title="' . esc_attr( $post_type_object->labels->name ) . '"><span itemprop="name">' . $post_type_object->labels->name . '</span></a></span>';
				}
				if ( isset( $args[ "singular_{$post_type}_taxonomy" ] ) && is_taxonomy_hierarchical( $args[ "singular_{$post_type}_taxonomy" ] ) ) {
					$terms = wp_get_object_terms( $post_id, $args[ "singular_{$post_type}_taxonomy" ] );
					if ( isset( $terms[0] ) ) {
						$item = array_merge( $item, astra_breadcrumb_get_term_parents( $terms[0], $args[ "singular_{$post_type}_taxonomy" ] ) );
					}
				} elseif ( isset( $args[ "singular_{$post_type}_taxonomy" ] ) ) {
					$item[] = get_the_term_list( $post_id, $args[ "singular_{$post_type}_taxonomy" ], '', ', ', '' );
				}
			}
			$post_parent = ( isset( $wp_query->post->post_parent ) ) ? $wp_query->post->post_parent : '';
			$parents     = astra_breadcrumb_get_parents( $post_parent );
			if ( ( is_post_type_hierarchical( $wp_query->post->post_type ) || 'attachment' === $wp_query->post->post_type ) && $parents ) {
				$item = array_merge( $item, $parents );
			}
			$item['last'] = '<span itemprop="name">' . get_the_title() . '</span>';
			// If viewing any type of archive.
		} elseif ( is_archive() ) {
			if ( is_category() || is_tag() || is_tax() ) {
				$term     = $wp_query->get_queried_object();
				$taxonomy = get_taxonomy( $term->taxonomy );
				$parents  = astra_breadcrumb_get_term_parents( $term->parent, $term->taxonomy );
				if ( ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent ) && $parents ) {
					$item = array_merge( $item, $parents );
				}
				$item['last'] = '<span itemprop="name">' . $term->name . '</span>';
			} elseif ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
				$post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
				$item['last']     = '<span itemprop="name">' . $post_type_object->labels->name . '</span>';
			} elseif ( is_date() ) {
				if ( is_day() ) {
					$item['last'] = '<span itemprop="name">' . $args['archive-prefix'] . get_the_time( 'F j, Y' ) . '</span>';
				} elseif ( is_month() ) {
					$item['last'] = '<span itemprop="name">' . $args['archive-prefix'] . single_month_title( ' ', false ) . '</span>';
				} elseif ( is_year() ) {
					$item['last'] = '<span itemprop="name">' . $args['archive-prefix'] . get_the_time( 'Y' ) . '</span>';
				}
			} elseif ( is_author() ) {
				$item['last'] = '<span itemprop="name">' . $args['author-prefix'] . get_the_author_meta( 'display_name', ( isset( $wp_query->post->post_author ) ) ? $wp_query->post->post_author : '' ) . '</span>';
			}
			// If viewing search results.
		} elseif ( is_search() ) {
			$item['last'] = '<span itemprop="name">' . $args['search-prefix'] . stripslashes( wp_strip_all_tags( get_search_query() ) ) . '</span>';
			// If viewing a 404 error page.
		} elseif ( is_404() ) {
			$item['last'] = '<span itemprop="name">' . $args['404-title'] . '</span>';
		}

		$keys      = array_keys( $item );
		$index_max = count( $item );
		for ( $index = 0;  $index < $index_max; $index++ ) {
			$item[ $keys[ $index ] ] = str_replace( '${content}', $index + 1, $item[ $keys[ $index ] ] );
		}

		return apply_filters( 'astra_breadcrumb_items', $item );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.