did some sniff sniff
This commit is contained in:
@@ -35,8 +35,9 @@ function breadcrumb_trail( $args = array() ) {
|
||||
|
||||
$breadcrumb = apply_filters( 'breadcrumb_trail_object', null, $args );
|
||||
|
||||
if ( ! is_object( $breadcrumb ) )
|
||||
if ( ! is_object( $breadcrumb ) ) {
|
||||
$breadcrumb = new Breadcrumb_Trail( $args );
|
||||
}
|
||||
|
||||
return $breadcrumb->trail();
|
||||
}
|
||||
@@ -105,7 +106,7 @@ class Breadcrumb_Trail {
|
||||
*
|
||||
* @since 0.6.0
|
||||
* @access public
|
||||
* @param array $args {
|
||||
* @param array $args {
|
||||
* @type string $container Container HTML element. nav|div
|
||||
* @type string $before String to output before breadcrumb menu.
|
||||
* @type string $after String to output after breadcrumb menu.
|
||||
@@ -125,19 +126,19 @@ class Breadcrumb_Trail {
|
||||
public function __construct( $args = array() ) {
|
||||
|
||||
$defaults = array(
|
||||
'container' => 'nav',
|
||||
'before' => '',
|
||||
'after' => '',
|
||||
'browse_tag' => 'h2',
|
||||
'list_tag' => 'ul',
|
||||
'item_tag' => 'li',
|
||||
'show_on_front' => true,
|
||||
'network' => false,
|
||||
'show_title' => true,
|
||||
'show_browse' => true,
|
||||
'labels' => array(),
|
||||
'post_taxonomy' => array(),
|
||||
'echo' => true
|
||||
'container' => 'nav',
|
||||
'before' => '',
|
||||
'after' => '',
|
||||
'browse_tag' => 'h2',
|
||||
'list_tag' => 'ul',
|
||||
'item_tag' => 'li',
|
||||
'show_on_front' => true,
|
||||
'network' => false,
|
||||
'show_title' => true,
|
||||
'show_browse' => true,
|
||||
'labels' => array(),
|
||||
'post_taxonomy' => array(),
|
||||
'echo' => true,
|
||||
);
|
||||
|
||||
// Parse the arguments with the deaults.
|
||||
@@ -210,11 +211,12 @@ class Breadcrumb_Trail {
|
||||
// Add list item classes.
|
||||
$item_class = 'trail-item';
|
||||
|
||||
if ( 1 === $item_position && 1 < $item_count )
|
||||
if ( 1 === $item_position && 1 < $item_count ) {
|
||||
$item_class .= ' trail-begin';
|
||||
|
||||
elseif ( $item_count === $item_position )
|
||||
} elseif ( $item_count === $item_position ) {
|
||||
$item_class .= ' trail-end';
|
||||
}
|
||||
|
||||
// Create list item attributes.
|
||||
$attributes = 'itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" class="' . $item_class . '"';
|
||||
@@ -223,7 +225,7 @@ class Breadcrumb_Trail {
|
||||
$meta = sprintf( '<meta itemprop="position" content="%s" />', absint( $item_position ) );
|
||||
|
||||
// Build the list item.
|
||||
$breadcrumb .= sprintf( '<%1$s %2$s>%3$s%4$s</%1$s>', tag_escape( $this->args['item_tag'] ),$attributes, $item, $meta );
|
||||
$breadcrumb .= sprintf( '<%1$s %2$s>%3$s%4$s</%1$s>', tag_escape( $this->args['item_tag'] ), $attributes, $item, $meta );
|
||||
}
|
||||
|
||||
// Close the unordered list.
|
||||
@@ -243,8 +245,9 @@ class Breadcrumb_Trail {
|
||||
// Allow developers to filter the breadcrumb trail HTML.
|
||||
$breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb, $this->args );
|
||||
|
||||
if ( false === $this->args['echo'] )
|
||||
if ( false === $this->args['echo'] ) {
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
echo $breadcrumb;
|
||||
}
|
||||
@@ -261,21 +264,21 @@ class Breadcrumb_Trail {
|
||||
protected function set_labels() {
|
||||
|
||||
$defaults = array(
|
||||
'browse' => esc_html__( 'Browse:', 'sophia-after-dark' ),
|
||||
'browse' => esc_html__( 'Browse:', 'sophia-after-dark' ),
|
||||
'aria_label' => esc_attr_x( 'Breadcrumbs', 'breadcrumbs aria label', 'sophia-after-dark' ),
|
||||
'home' => esc_html__( 'Home', 'sophia-after-dark' ),
|
||||
'error_404' => esc_html__( '404 Not Found', 'sophia-after-dark' ),
|
||||
'archives' => esc_html__( 'Archives', 'sophia-after-dark' ),
|
||||
'home' => esc_html__( 'Home', 'sophia-after-dark' ),
|
||||
'error_404' => esc_html__( '404 Not Found', 'sophia-after-dark' ),
|
||||
'archives' => esc_html__( 'Archives', 'sophia-after-dark' ),
|
||||
// Translators: %s is the search query.
|
||||
'search' => esc_html__( 'Search results for: %s', 'sophia-after-dark' ),
|
||||
'search' => esc_html__( 'Search results for: %s', 'sophia-after-dark' ),
|
||||
// Translators: %s is the page number.
|
||||
'paged' => esc_html__( 'Page %s', 'sophia-after-dark' ),
|
||||
'paged' => esc_html__( 'Page %s', 'sophia-after-dark' ),
|
||||
// Translators: %s is the page number.
|
||||
'paged_comments' => esc_html__( 'Comment Page %s', 'sophia-after-dark' ),
|
||||
'paged_comments' => esc_html__( 'Comment Page %s', 'sophia-after-dark' ),
|
||||
// Translators: Minute archive title. %s is the minute time format.
|
||||
'archive_minute' => esc_html__( 'Minute %s', 'sophia-after-dark' ),
|
||||
'archive_minute' => esc_html__( 'Minute %s', 'sophia-after-dark' ),
|
||||
// Translators: Weekly archive title. %s is the week date format.
|
||||
'archive_week' => esc_html__( 'Week %s', 'sophia-after-dark' ),
|
||||
'archive_week' => esc_html__( 'Week %s', 'sophia-after-dark' ),
|
||||
|
||||
// "%s" is replaced with the translated date/time format.
|
||||
'archive_minute_hour' => '%s',
|
||||
@@ -301,8 +304,9 @@ class Breadcrumb_Trail {
|
||||
$defaults = array();
|
||||
|
||||
// If post permalink is set to `%postname%`, use the `category` taxonomy.
|
||||
if ( '%postname%' === trim( get_option( 'permalink_structure' ), '/' ) )
|
||||
if ( '%postname%' === trim( get_option( 'permalink_structure' ), '/' ) ) {
|
||||
$defaults['post'] = 'category';
|
||||
}
|
||||
|
||||
$this->post_taxonomy = apply_filters( 'breadcrumb_trail_post_taxonomy', wp_parse_args( $this->args['post_taxonomy'], $defaults ) );
|
||||
}
|
||||
@@ -342,38 +346,39 @@ class Breadcrumb_Trail {
|
||||
// If viewing an archive page.
|
||||
elseif ( is_archive() ) {
|
||||
|
||||
if ( is_post_type_archive() )
|
||||
if ( is_post_type_archive() ) {
|
||||
$this->add_post_type_archive_items();
|
||||
|
||||
elseif ( is_category() || is_tag() || is_tax() )
|
||||
} elseif ( is_category() || is_tag() || is_tax() ) {
|
||||
$this->add_term_archive_items();
|
||||
|
||||
elseif ( is_author() )
|
||||
} elseif ( is_author() ) {
|
||||
$this->add_user_archive_items();
|
||||
|
||||
elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) )
|
||||
} elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) ) {
|
||||
$this->add_minute_hour_archive_items();
|
||||
|
||||
elseif ( get_query_var( 'minute' ) )
|
||||
} elseif ( get_query_var( 'minute' ) ) {
|
||||
$this->add_minute_archive_items();
|
||||
|
||||
elseif ( get_query_var( 'hour' ) )
|
||||
} elseif ( get_query_var( 'hour' ) ) {
|
||||
$this->add_hour_archive_items();
|
||||
|
||||
elseif ( is_day() )
|
||||
} elseif ( is_day() ) {
|
||||
$this->add_day_archive_items();
|
||||
|
||||
elseif ( get_query_var( 'w' ) )
|
||||
} elseif ( get_query_var( 'w' ) ) {
|
||||
$this->add_week_archive_items();
|
||||
|
||||
elseif ( is_month() )
|
||||
} elseif ( is_month() ) {
|
||||
$this->add_month_archive_items();
|
||||
|
||||
elseif ( is_year() )
|
||||
} elseif ( is_year() ) {
|
||||
$this->add_year_archive_items();
|
||||
|
||||
else
|
||||
} else {
|
||||
$this->add_default_archive_items();
|
||||
}
|
||||
}
|
||||
|
||||
// If viewing a search results page.
|
||||
@@ -404,8 +409,9 @@ class Breadcrumb_Trail {
|
||||
protected function add_rewrite_front_items() {
|
||||
global $wp_rewrite;
|
||||
|
||||
if ( $wp_rewrite->front )
|
||||
if ( $wp_rewrite->front ) {
|
||||
$this->add_path_parents( $wp_rewrite->front );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,16 +424,19 @@ class Breadcrumb_Trail {
|
||||
protected function add_paged_items() {
|
||||
|
||||
// If viewing a paged singular post.
|
||||
if ( is_singular() && 1 < get_query_var( 'page' ) && true === $this->args['show_title'] )
|
||||
if ( is_singular() && 1 < get_query_var( 'page' ) && true === $this->args['show_title'] ) {
|
||||
$this->items[] = sprintf( $this->labels['paged'], number_format_i18n( absint( get_query_var( 'page' ) ) ) );
|
||||
}
|
||||
|
||||
// If viewing a singular post with paged comments.
|
||||
elseif ( is_singular() && get_option( 'page_comments' ) && 1 < get_query_var( 'cpage' ) )
|
||||
elseif ( is_singular() && get_option( 'page_comments' ) && 1 < get_query_var( 'cpage' ) ) {
|
||||
$this->items[] = sprintf( $this->labels['paged_comments'], number_format_i18n( absint( get_query_var( 'cpage' ) ) ) );
|
||||
}
|
||||
|
||||
// If viewing a paged archive-type page.
|
||||
elseif ( is_paged() && true === $this->args['show_title'] )
|
||||
elseif ( is_paged() && true === $this->args['show_title'] ) {
|
||||
$this->items[] = sprintf( $this->labels['paged'], number_format_i18n( absint( get_query_var( 'paged' ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -439,8 +448,9 @@ class Breadcrumb_Trail {
|
||||
*/
|
||||
protected function add_network_home_link() {
|
||||
|
||||
if ( is_multisite() && ! is_main_site() && true === $this->args['network'] )
|
||||
if ( is_multisite() && ! is_main_site() && true === $this->args['network'] ) {
|
||||
$this->items[] = sprintf( '<a href="%s" rel="home">%s</a>', esc_url( network_home_url() ), $this->labels['home'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -475,12 +485,14 @@ class Breadcrumb_Trail {
|
||||
$this->add_network_home_link();
|
||||
|
||||
// If on a paged view, add the site home link.
|
||||
if ( is_paged() )
|
||||
if ( is_paged() ) {
|
||||
$this->add_site_home_link();
|
||||
}
|
||||
|
||||
// If on the main front page, add the network home title.
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = is_multisite() && true === $this->args['network'] ? get_bloginfo( 'name' ) : $this->labels['home'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,18 +510,20 @@ class Breadcrumb_Trail {
|
||||
$post = get_post( $post_id );
|
||||
|
||||
// If the post has parents, add them to the trail.
|
||||
if ( 0 < $post->post_parent )
|
||||
if ( 0 < $post->post_parent ) {
|
||||
$this->add_post_parents( $post->post_parent );
|
||||
}
|
||||
|
||||
// Get the page title.
|
||||
$title = get_the_title( $post_id );
|
||||
|
||||
// Add the posts page item.
|
||||
if ( is_paged() )
|
||||
if ( is_paged() ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), $title );
|
||||
|
||||
elseif ( $title && true === $this->args['show_title'] )
|
||||
} elseif ( $title && true === $this->args['show_title'] ) {
|
||||
$this->items[] = $title;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -526,25 +540,29 @@ class Breadcrumb_Trail {
|
||||
$post_id = get_queried_object_id();
|
||||
|
||||
// If the post has a parent, follow the parent trail.
|
||||
if ( 0 < $post->post_parent )
|
||||
if ( 0 < $post->post_parent ) {
|
||||
$this->add_post_parents( $post->post_parent );
|
||||
}
|
||||
|
||||
// If the post doesn't have a parent, get its hierarchy based off the post type.
|
||||
else
|
||||
else {
|
||||
$this->add_post_hierarchy( $post_id );
|
||||
}
|
||||
|
||||
// Display terms for specific post type taxonomy if requested.
|
||||
if ( ! empty( $this->post_taxonomy[ $post->post_type ] ) )
|
||||
if ( ! empty( $this->post_taxonomy[ $post->post_type ] ) ) {
|
||||
$this->add_post_terms( $post_id, $this->post_taxonomy[ $post->post_type ] );
|
||||
}
|
||||
|
||||
// End with the post title.
|
||||
if ( $post_title = single_post_title( '', false ) ) {
|
||||
|
||||
if ( ( 1 < get_query_var( 'page' ) || is_paged() ) || ( get_option( 'page_comments' ) && 1 < absint( get_query_var( 'cpage' ) ) ) )
|
||||
if ( ( 1 < get_query_var( 'page' ) || is_paged() ) || ( get_option( 'page_comments' ) && 1 < absint( get_query_var( 'cpage' ) ) ) ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), $post_title );
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = $post_title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,8 +586,9 @@ class Breadcrumb_Trail {
|
||||
if ( false !== $taxonomy->rewrite ) {
|
||||
|
||||
// If 'with_front' is true, dd $wp_rewrite->front to the trail.
|
||||
if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
|
||||
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'] );
|
||||
@@ -629,10 +648,11 @@ class Breadcrumb_Trail {
|
||||
if ( 'post' === $taxonomy->object_type[0] ) {
|
||||
$post_id = get_option( 'page_for_posts' );
|
||||
|
||||
if ( 'posts' !== get_option( 'show_on_front' ) && 0 < $post_id )
|
||||
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'.
|
||||
// If the post type is not 'post'.
|
||||
} else {
|
||||
$post_type_object = get_post_type_object( $taxonomy->object_type[0] );
|
||||
|
||||
@@ -646,15 +666,17 @@ class Breadcrumb_Trail {
|
||||
}
|
||||
|
||||
// If the taxonomy is hierarchical, list its parent terms.
|
||||
if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent )
|
||||
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() )
|
||||
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'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = single_term_title( '', false );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -672,24 +694,28 @@ class Breadcrumb_Trail {
|
||||
if ( false !== $post_type_object->rewrite ) {
|
||||
|
||||
// If 'with_front' is true, add $wp_rewrite->front to the trail.
|
||||
if ( $post_type_object->rewrite['with_front'] )
|
||||
if ( $post_type_object->rewrite['with_front'] ) {
|
||||
$this->add_rewrite_front_items();
|
||||
}
|
||||
|
||||
// If there's a rewrite slug, check for parents.
|
||||
if ( ! empty( $post_type_object->rewrite['slug'] ) )
|
||||
if ( ! empty( $post_type_object->rewrite['slug'] ) ) {
|
||||
$this->add_path_parents( $post_type_object->rewrite['slug'] );
|
||||
}
|
||||
}
|
||||
|
||||
// Add the post type [plural] name to the trail end.
|
||||
if ( is_paged() || is_author() )
|
||||
if ( is_paged() || is_author() ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $post_type_object->name ) ), post_type_archive_title( '', false ) );
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = post_type_archive_title( '', false );
|
||||
}
|
||||
|
||||
// If viewing a post type archive by author.
|
||||
if ( is_author() )
|
||||
if ( is_author() ) {
|
||||
$this->add_user_archive_items();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -710,15 +736,17 @@ class Breadcrumb_Trail {
|
||||
$user_id = get_query_var( 'author' );
|
||||
|
||||
// If $author_base exists, check for parent pages.
|
||||
if ( ! empty( $wp_rewrite->author_base ) && ! is_post_type_archive() )
|
||||
if ( ! empty( $wp_rewrite->author_base ) && ! is_post_type_archive() ) {
|
||||
$this->add_path_parents( $wp_rewrite->author_base );
|
||||
}
|
||||
|
||||
// Add the author's display name to the trail end.
|
||||
if ( is_paged() )
|
||||
if ( is_paged() ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_author_posts_url( $user_id ) ), get_the_author_meta( 'display_name', $user_id ) );
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = get_the_author_meta( 'display_name', $user_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -734,8 +762,9 @@ class Breadcrumb_Trail {
|
||||
$this->add_rewrite_front_items();
|
||||
|
||||
// Add the minute + hour item.
|
||||
if ( true === $this->args['show_title'] )
|
||||
if ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = sprintf( $this->labels['archive_minute_hour'], get_the_time( esc_html_x( 'g:i a', 'minute and hour archives time format', 'sophia-after-dark' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -751,8 +780,9 @@ class Breadcrumb_Trail {
|
||||
$this->add_rewrite_front_items();
|
||||
|
||||
// Add the minute item.
|
||||
if ( true === $this->args['show_title'] )
|
||||
if ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = sprintf( $this->labels['archive_minute'], get_the_time( esc_html_x( 'i', 'minute archives time format', 'sophia-after-dark' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -768,8 +798,9 @@ class Breadcrumb_Trail {
|
||||
$this->add_rewrite_front_items();
|
||||
|
||||
// Add the hour item.
|
||||
if ( true === $this->args['show_title'] )
|
||||
if ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = sprintf( $this->labels['archive_hour'], get_the_time( esc_html_x( 'g a', 'hour archives time format', 'sophia-after-dark' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -785,20 +816,21 @@ class Breadcrumb_Trail {
|
||||
$this->add_rewrite_front_items();
|
||||
|
||||
// Get year, month, and day.
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
$month = sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'sophia-after-dark' ) ) );
|
||||
$day = sprintf( $this->labels['archive_day'], get_the_time( esc_html_x( 'j', 'daily archives date format', 'sophia-after-dark' ) ) );
|
||||
$day = sprintf( $this->labels['archive_day'], get_the_time( esc_html_x( 'j', 'daily archives date format', 'sophia-after-dark' ) ) );
|
||||
|
||||
// Add the year and month items.
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ), $month );
|
||||
|
||||
// Add the day item.
|
||||
if ( is_paged() )
|
||||
if ( is_paged() ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_day_link( get_the_time( 'Y' ) ), get_the_time( 'm' ), get_the_time( 'd' ) ), $day );
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = $day;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -814,18 +846,31 @@ class Breadcrumb_Trail {
|
||||
$this->add_rewrite_front_items();
|
||||
|
||||
// Get the year and week.
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
$week = sprintf( $this->labels['archive_week'], get_the_time( esc_html_x( 'W', 'weekly archives date format', 'sophia-after-dark' ) ) );
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
$week = sprintf( $this->labels['archive_week'], get_the_time( esc_html_x( 'W', 'weekly archives date format', 'sophia-after-dark' ) ) );
|
||||
|
||||
// Add the year item.
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
|
||||
|
||||
// Add the week item.
|
||||
if ( is_paged() )
|
||||
$this->items[] = esc_url( get_archives_link( add_query_arg( array( 'm' => get_the_time( 'Y' ), 'w' => get_the_time( 'W' ) ), home_url() ), $week, false ) );
|
||||
if ( is_paged() ) {
|
||||
$this->items[] = esc_url(
|
||||
get_archives_link(
|
||||
add_query_arg(
|
||||
array(
|
||||
'm' => get_the_time( 'Y' ),
|
||||
'w' => get_the_time( 'W' ),
|
||||
),
|
||||
home_url()
|
||||
),
|
||||
$week,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = $week;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -841,18 +886,19 @@ class Breadcrumb_Trail {
|
||||
$this->add_rewrite_front_items();
|
||||
|
||||
// Get the year and month.
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
$month = sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'sophia-after-dark' ) ) );
|
||||
|
||||
// Add the year item.
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
|
||||
|
||||
// Add the month item.
|
||||
if ( is_paged() )
|
||||
if ( is_paged() ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ), $month );
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = $month;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -868,14 +914,15 @@ class Breadcrumb_Trail {
|
||||
$this->add_rewrite_front_items();
|
||||
|
||||
// Get the year.
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
$year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) );
|
||||
|
||||
// Add the year item.
|
||||
if ( is_paged() )
|
||||
if ( is_paged() ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = $year;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -889,11 +936,13 @@ class Breadcrumb_Trail {
|
||||
protected function add_default_archive_items() {
|
||||
|
||||
// If this is a date-/time-based archive, add $wp_rewrite->front to the trail.
|
||||
if ( is_date() || is_time() )
|
||||
if ( is_date() || is_time() ) {
|
||||
$this->add_rewrite_front_items();
|
||||
}
|
||||
|
||||
if ( true === $this->args['show_title'] )
|
||||
if ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = $this->labels['archives'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -905,11 +954,12 @@ class Breadcrumb_Trail {
|
||||
*/
|
||||
protected function add_search_items() {
|
||||
|
||||
if ( is_paged() )
|
||||
if ( is_paged() ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_search_link() ), sprintf( $this->labels['search'], get_search_query() ) );
|
||||
|
||||
elseif ( true === $this->args['show_title'] )
|
||||
} elseif ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = sprintf( $this->labels['search'], get_search_query() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -921,8 +971,9 @@ class Breadcrumb_Trail {
|
||||
*/
|
||||
protected function add_404_items() {
|
||||
|
||||
if ( true === $this->args['show_title'] )
|
||||
if ( true === $this->args['show_title'] ) {
|
||||
$this->items[] = $this->labels['error_404'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -930,7 +981,7 @@ class Breadcrumb_Trail {
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @param int $post_id
|
||||
* @param int $post_id
|
||||
* @return void
|
||||
*/
|
||||
protected function add_post_parents( $post_id ) {
|
||||
@@ -942,15 +993,17 @@ class Breadcrumb_Trail {
|
||||
$post = get_post( $post_id );
|
||||
|
||||
// If we hit a page that's set as the front page, bail.
|
||||
if ( 'page' == $post->post_type && 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) )
|
||||
if ( 'page' == $post->post_type && 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the formatted post link to the array of parents.
|
||||
$parents[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), get_the_title( $post_id ) );
|
||||
|
||||
// If there's no longer a post parent, break out of the loop.
|
||||
if ( 0 >= $post->post_parent )
|
||||
if ( 0 >= $post->post_parent ) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Change the post ID to the parent post to continue looping.
|
||||
$post_id = $post->post_parent;
|
||||
@@ -960,8 +1013,9 @@ class Breadcrumb_Trail {
|
||||
$this->add_post_hierarchy( $post_id );
|
||||
|
||||
// Display terms for specific post type taxonomy if requested.
|
||||
if ( ! empty( $this->post_taxonomy[ $post->post_type ] ) )
|
||||
if ( ! empty( $this->post_taxonomy[ $post->post_type ] ) ) {
|
||||
$this->add_post_terms( $post_id, $this->post_taxonomy[ $post->post_type ] );
|
||||
}
|
||||
|
||||
// Merge the parent items into the items array.
|
||||
$this->items = array_merge( $this->items, array_reverse( $parents ) );
|
||||
@@ -973,7 +1027,7 @@ class Breadcrumb_Trail {
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @param int $post_id
|
||||
* @param int $post_id
|
||||
* @return void
|
||||
*/
|
||||
protected function add_post_hierarchy( $post_id ) {
|
||||
@@ -996,12 +1050,14 @@ class Breadcrumb_Trail {
|
||||
elseif ( false !== $post_type_object->rewrite ) {
|
||||
|
||||
// If 'with_front' is true, add $wp_rewrite->front to the trail.
|
||||
if ( $post_type_object->rewrite['with_front'] )
|
||||
if ( $post_type_object->rewrite['with_front'] ) {
|
||||
$this->add_rewrite_front_items();
|
||||
}
|
||||
|
||||
// If there's a path, check for parents.
|
||||
if ( ! empty( $post_type_object->rewrite['slug'] ) )
|
||||
if ( ! empty( $post_type_object->rewrite['slug'] ) ) {
|
||||
$this->add_path_parents( $post_type_object->rewrite['slug'] );
|
||||
}
|
||||
}
|
||||
|
||||
// If there's an archive page, add it to the trail.
|
||||
@@ -1017,8 +1073,9 @@ class Breadcrumb_Trail {
|
||||
}
|
||||
|
||||
// Map the rewrite tags if there's a `%` in the slug.
|
||||
if ( 'post' !== $post_type && ! empty( $post_type_object->rewrite['slug'] ) && false !== strpos( $post_type_object->rewrite['slug'], '%' ) )
|
||||
if ( 'post' !== $post_type && ! empty( $post_type_object->rewrite['slug'] ) && false !== strpos( $post_type_object->rewrite['slug'], '%' ) ) {
|
||||
$this->map_rewrite_tags( $post_id, $post_type_object->rewrite['slug'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1027,7 +1084,7 @@ class Breadcrumb_Trail {
|
||||
*
|
||||
* @since 0.6.0
|
||||
* @access protected
|
||||
* @param int $slug The post type archive slug to search for.
|
||||
* @param int $slug The post type archive slug to search for.
|
||||
* @return void
|
||||
*/
|
||||
protected function get_post_types_by_slug( $slug ) {
|
||||
@@ -1038,8 +1095,9 @@ class Breadcrumb_Trail {
|
||||
|
||||
foreach ( $post_types as $type ) {
|
||||
|
||||
if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) )
|
||||
if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) ) {
|
||||
$return[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
@@ -1050,8 +1108,8 @@ class Breadcrumb_Trail {
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @param int $post_id The ID of the post to get the terms for.
|
||||
* @param string $taxonomy The taxonomy to get the terms from.
|
||||
* @param int $post_id The ID of the post to get the terms for.
|
||||
* @param string $taxonomy The taxonomy to get the terms from.
|
||||
* @return void
|
||||
*/
|
||||
protected function add_post_terms( $post_id, $taxonomy ) {
|
||||
@@ -1066,17 +1124,19 @@ class Breadcrumb_Trail {
|
||||
if ( $terms && ! is_wp_error( $terms ) ) {
|
||||
|
||||
// Sort the terms by ID and get the first category.
|
||||
if ( function_exists( 'wp_list_sort' ) )
|
||||
if ( function_exists( 'wp_list_sort' ) ) {
|
||||
$terms = wp_list_sort( $terms, 'term_id' );
|
||||
|
||||
else
|
||||
} else {
|
||||
usort( $terms, '_usort_terms_by_ID' );
|
||||
}
|
||||
|
||||
$term = get_term( $terms[0], $taxonomy );
|
||||
|
||||
// If the category has a parent, add the hierarchy to the trail.
|
||||
if ( 0 < $term->parent )
|
||||
if ( 0 < $term->parent ) {
|
||||
$this->add_term_parents( $term->parent, $taxonomy );
|
||||
}
|
||||
|
||||
// Add the category archive link to the trail.
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $taxonomy ) ), $term->name );
|
||||
@@ -1099,21 +1159,20 @@ class Breadcrumb_Trail {
|
||||
$path = trim( $path, '/' );
|
||||
|
||||
// If there's no path, return.
|
||||
if ( empty( $path ) )
|
||||
if ( empty( $path ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get parent post by the path.
|
||||
$post = get_page_by_path( $path );
|
||||
|
||||
if ( ! empty( $post ) ) {
|
||||
$this->add_post_parents( $post->ID );
|
||||
}
|
||||
|
||||
elseif ( is_null( $post ) ) {
|
||||
} elseif ( is_null( $post ) ) {
|
||||
|
||||
// Separate post names into separate paths by '/'.
|
||||
$path = trim( $path, '/' );
|
||||
preg_match_all( "/\/.*?\z/", $path, $matches );
|
||||
preg_match_all( '/\/.*?\z/', $path, $matches );
|
||||
|
||||
// If matches are found for the path.
|
||||
if ( isset( $matches ) ) {
|
||||
@@ -1170,8 +1229,9 @@ class Breadcrumb_Trail {
|
||||
}
|
||||
|
||||
// If we have parent terms, reverse the array to put them in the proper order for the trail.
|
||||
if ( ! empty( $parents ) )
|
||||
if ( ! empty( $parents ) ) {
|
||||
$this->items = array_merge( $this->items, array_reverse( $parents ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1207,20 +1267,24 @@ class Breadcrumb_Trail {
|
||||
$tag = trim( $match, '/' );
|
||||
|
||||
// If using the %year% tag, add a link to the yearly archive.
|
||||
if ( '%year%' == $tag )
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y', $post_id ) ) ), sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) ) );
|
||||
if ( '%year%' == $tag ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y', $post_id ) ) ), sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'sophia-after-dark' ) ) ) );
|
||||
}
|
||||
|
||||
// If using the %monthnum% tag, add a link to the monthly archive.
|
||||
elseif ( '%monthnum%' == $tag )
|
||||
elseif ( '%monthnum%' == $tag ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ) ) ), sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'sophia-after-dark' ) ) ) );
|
||||
}
|
||||
|
||||
// If using the %day% tag, add a link to the daily archive.
|
||||
elseif ( '%day%' == $tag )
|
||||
elseif ( '%day%' == $tag ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_day_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ), get_the_time( 'd', $post_id ) ) ), sprintf( $this->labels['archive_day'], get_the_time( esc_html_x( 'j', 'daily archives date format', 'sophia-after-dark' ) ) ) );
|
||||
}
|
||||
|
||||
// If using the %author% tag, add a link to the post author archive.
|
||||
elseif ( '%author%' == $tag )
|
||||
elseif ( '%author%' == $tag ) {
|
||||
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_author_posts_url( $post->post_author ) ), get_the_author_meta( 'display_name', $post->post_author ) );
|
||||
}
|
||||
|
||||
// If using the %category% tag, add a link to the first category archive to match permalinks.
|
||||
elseif ( taxonomy_exists( trim( $tag, '%' ) ) ) {
|
||||
@@ -1234,4 +1298,4 @@ class Breadcrumb_Trail {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user