Astra_Breadcrumb_Trail::map_rewrite_tags( int $post_id, string $path )
Turns %tag% from permalink structures into usable links for the breadcrumb trail. This feels kind of hackish for now because we’re checking for specific %tag% examples and only doing it for the ‘post’ post type. In the future, maybe it’ll handle a wider variety of possibilities, especially for custom post types.
Description
Parameters
- $post_id
-
(int) (Required) ID of the post whose parents we want.
- $path
-
(string) (Required) Path of a potential parent page.
- $args
-
(array) (Required) Mixed arguments for the menu.
Return
(array)
Source
File: inc/addons/breadcrumbs/class-astra-breadcrumb-trail.php
protected function map_rewrite_tags( $post_id, $path ) { $post = get_post( $post_id ); // Trim '/' from both sides of the $path. $path = trim( $path, '/' ); // Split the $path into an array of strings. $matches = explode( '/', $path ); // If matches are found for the path. if ( is_array( $matches ) ) { // Loop through each of the matches, adding each to the $trail array. foreach ( $matches as $match ) { // Trim any '/' from the $match. $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', 'astra' ) ) ) ); } // If using the %monthnum% tag, add a link to the monthly archive. 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', 'astra' ) ) ) ); } // If using the %day% tag, add a link to the daily archive. 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', 'astra' ) ) ) ); } // If using the %author% tag, add a link to the post author archive. 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, '%' ) ) ) { // Force override terms in this post type. $this->post_taxonomy[ $post->post_type ] = false; // Add the post categories. $this->add_post_terms( $post_id, trim( $tag, '%' ) ); } } } }
Expand full source code Collapse full source code View on Trac
Changelog
Version | Description |
---|---|
0.6.0 | Introduced. |