Changeset 10169 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-breadcrumbs.php
- Timestamp:
- 08/13/2020 11:43:14 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-breadcrumbs.php
r10131 r10169 10 10 /** 11 11 * Returns list of workshops based on slug 12 * 12 * 13 13 * @return array|bool 14 14 */ 15 15 function get_workshop_from_slug( $slug ) { 16 $args = array(17 'name' => $slug,18 'post_type' => 'workshop',19 'post_status' => 'publish',20 'numberposts' => 1 21 );16 $args = array( 17 'name' => $slug, 18 'post_type' => 'workshop', 19 'post_status' => 'publish', 20 'numberposts' => 1, 21 ); 22 22 23 $workshop = get_posts( $args );23 $workshop = get_posts( $args ); 24 24 25 return isset( $workshop[ 0 ] ) ? $workshop[ 0] : false;25 return isset( $workshop[0] ) ? $workshop[0] : false; 26 26 } 27 27 28 28 /** 29 29 * Returns whether we are viewing a lesson from a workshop 30 * 30 * 31 31 * @param string $referer 32 32 * @return bool 33 33 */ 34 34 function lesson_came_from_workshop( $referer ) { 35 return wporg_post_type_is_lesson() && strrpos( $referer, 'workshop' );35 return wporg_post_type_is_lesson() && strrpos( $referer, 'workshop' ); 36 36 } 37 37 38 $crumbs = [39 [ 40 'label' => __( 'Learn Home', 'wporg-learn' ),41 'url' => home_url() 42 ] 43 ];38 $crumbs = array( 39 array( 40 'label' => __( 'Learn Home', 'wporg-learn' ), 41 'url' => home_url(), 42 ), 43 ); 44 44 45 45 $referer = wp_get_referer(); 46 46 47 // If we came from a workshop, we want to modify the breadrumbs to bring us back to the workshop 48 if ( lesson_came_from_workshop( $referer ) ) {49 $workshop = get_workshop_from_slug( basename( $referer ) );47 // If we came from a workshop, we want to modify the breadrumbs to bring us back to the workshop. 48 if ( lesson_came_from_workshop( $referer ) ) { 49 $workshop = get_workshop_from_slug( basename( $referer ) ); 50 50 51 if( $workshop ) {52 array_push( $crumbs, [ 53 'label' => __( 'Workshops', 'wporg-learn' ),54 'url' => get_post_type_archive_link( 'workshop' ) 55 ]);51 if ( $workshop ) { 52 array_push( $crumbs, array( 53 'label' => __( 'Workshops', 'wporg-learn' ), 54 'url' => get_post_type_archive_link( 'workshop' ), 55 ) ); 56 56 57 array_push( $crumbs, [ 58 'label' => $workshop->post_title, 59 'url' => get_post_permalink( $workshop->ID ) 60 ] ); 61 } 62 57 array_push( $crumbs, array( 58 'label' => $workshop->post_title, 59 'url' => get_post_permalink( $workshop->ID ), 60 ) ); 61 } 63 62 } else { 64 63 65 // Get information about the post title.66 $post_type= get_post_type_object( get_post_type( get_queried_object() ) );64 // Get information about the post title. 65 $cpt_object = get_post_type_object( get_post_type( get_queried_object() ) ); 67 66 68 if( wporg_post_type_is_lesson() ){69 array_push( $crumbs, [ 70 'label' => ucfirst( $post_type->labels->name ),71 'url' => home_url( $post_type->has_archive ) 72 ]);73 }67 if ( wporg_post_type_is_lesson() ) { 68 array_push( $crumbs, array( 69 'label' => ucfirst( $cpt_object->labels->name ), 70 'url' => home_url( $cpt_object->has_archive ), 71 ) ); 72 } 74 73 } 75 74 76 array_push( $crumbs, [77 'label' => get_the_title(),78 'url' => '' 79 ]);75 array_push( $crumbs, array( 76 'label' => get_the_title(), 77 'url' => '', 78 ) ); 80 79 ?> 81 80 82 81 <div class="clearfix"> 83 <div class="bbp-breadcrumb"> 84 <?php 85 $crumb_length = count($crumbs);82 <div class="bbp-breadcrumb"> 83 <?php 84 $crumb_length = count( $crumbs ); 86 85 87 for( $x = 0; $x < $crumb_length; $x++ ) {88 if( empty( $crumbs[ $x ][ 'url'] ) ) {89 echo '<span class="bbp-breadcrumb-current">' . $crumbs[ $x ][ 'label' ]. '</span>';90 } else {91 echo '<a href="' . $crumbs[ $x ][ 'url' ] .'" class="bbp-breadcrumb-home">';92 echo $crumbs[ $x ][ 'label' ];93 echo '</a>';94 }86 for ( $x = 0; $x < $crumb_length; $x++ ) { 87 if ( empty( $crumbs[ $x ]['url'] ) ) { 88 echo '<span class="bbp-breadcrumb-current">' . esc_html( $crumbs[ $x ]['label'] ) . '</span>'; 89 } else { 90 echo '<a href="' . esc_url( $crumbs[ $x ]['url'] ) . '" class="bbp-breadcrumb-home">'; 91 echo esc_html( $crumbs[ $x ]['label'] ); 92 echo '</a>'; 93 } 95 94 96 if( $x < $crumb_length - 1 ) {97 echo ' <span class="bbp-breadcrumb-sep">»</span> ';98 } 99 }100 ?>101 </div>95 if ( $x < $crumb_length - 1 ) { 96 echo ' <span class="bbp-breadcrumb-sep">»</span> '; 97 } 98 } 99 ?> 100 </div> 102 101 </div>
Note: See TracChangeset
for help on using the changeset viewer.