Changeset 12285 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/archive-course.php
- Timestamp:
- 11/30/2022 01:10:35 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/archive-course.php
r12096 r12285 10 10 namespace WordPressdotorg\Theme; 11 11 12 $prev_category = ''; 13 $category_title = ''; 14 $category_description = ''; 12 $all_courses = array(); 13 $course_categories = array(); 14 $prev_category = ''; 15 $begin_new_category = false; 15 16 16 17 get_header(); … … 19 20 20 21 <main id="main" class="site-main"> 21 22 22 <section> 23 <div class="row align-middle between section-heading section-heading--with-space gutters"> 24 <?php the_archive_title( '<h1 class="section-heading_title h2 col-8">', '</h1>' ); ?> 25 <?php get_template_part( 'template-parts/component', 'archive-search' ); ?> 23 <div class="section-heading section-heading--with-space"> 24 <?php the_archive_title( '<h1 class="section-heading_title h2">', '</h1>' ); ?> 26 25 </div> 27 26 28 27 <hr> 29 28 30 31 32 29 <?php if ( have_posts() ) : ?> 30 <?php while ( have_posts() ) : 31 the_post(); 33 32 34 $prev_category; 35 $begin_new_category = false; 36 $categories = get_the_terms( get_the_ID(), 'course-category' ); 33 $categories = get_the_terms( get_the_ID(), 'course-category' ); 37 34 38 if ( isset( $categories[0] ) ) { 39 $category_title = $categories[0]->name; 40 $category_description = $categories[0]->description; 41 $begin_new_category = $category_title !== $prev_category; 42 } 35 if ( isset( $categories[0] ) ) { 36 $category_slug = $categories[0]->slug; 37 $category_title = $categories[0]->name; 38 $category_description = $categories[0]->description; 43 39 44 if ( $begin_new_category ) { 45 // Close the previous card-grid if there was a previous category 46 if ( ! empty( $prev_category ) ) { 47 echo '</div>'; 48 } 49 ?> 50 <h2 class="h4 course-category-header"><?php echo esc_html( $category_title ); ?></h2> 51 <?php 52 if ( $category_description ) { 53 echo '<div class="course-category-description">' . esc_html( $category_description ) . '</div>'; 54 } 55 ?> 56 <div class="card-grid card-grid_2"> 57 <?php 58 $prev_category = $category_title; 59 } 60 40 ob_start(); 61 41 get_template_part( 62 42 'template-parts/component', … … 64 44 wporg_learn_get_card_template_args( get_the_ID() ) 65 45 ); 66 endwhile; ?> 67 </div> 46 47 $all_courses[ $category_slug ]['name'] = $category_title; 48 $all_courses[ $category_slug ]['description'] = $category_description; 49 $all_courses[ $category_slug ]['courses'][] = ob_get_clean(); 50 } 51 52 endwhile; 53 54 if ( ! empty( $all_courses ) ) { ?> 55 <div class="section-intro"> 56 <div class="row between gutters"> 57 <p class="col-8"><?php esc_html_e( 'WordPress provides limitless ways for people to craft and grow their online presence. The content in these courses is delivered in multiple formats, with a focus on text and video, working towards practical learning objectives to help you become a better WordPress developer, designer, user, and contributor.', 'wporg-learn' ); ?></p> 58 <?php get_template_part( 'template-parts/component', 'archive-search' ); ?> 59 </div> 60 </div> 61 <nav class="section-nav"> 62 <ul> 63 <?php foreach ( $all_courses as $slug => $category ) { ?> 64 <li class="section-nav-item"> 65 <a href="#<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $category['name'] ); ?></a> 66 </li> 67 <?php } ?> 68 </ul> 69 </nav> 70 <hr> 71 <?php 72 foreach ( $all_courses as $slug => $category ) { 73 74 // Check for new category on each loop and output necessary content and markup 75 $begin_new_category = $slug !== $prev_category; 76 77 if ( $begin_new_category ) { 78 79 // Close the previous card-grid if there was a previous category 80 if ( ! empty( $prev_category ) ) { 81 echo '</div><hr>'; 82 } 83 84 // Print category title and description 85 echo '<h2 class="h4 course-category-header" id="' . esc_attr( $slug ) . '">' . esc_html( $category['name'] ) . '</h2>'; 86 if ( $category_description ) { 87 echo '<div class="course-category-description">' . esc_html( $category['description'] ) . '</div>'; 88 } 89 90 // Start a new card grid for the new category 91 echo '<div class="card-grid card-grid_2">'; 92 93 // Set variable to check for new category on next loop 94 $prev_category = $slug; 95 } 96 97 // Display card for each course 98 foreach ( $category['courses'] as $course ) { 99 echo wp_kses( $course, 'post' ); 100 } 101 } 102 103 echo '</div>'; 104 105 } ?> 106 68 107 <?php else : ?> 69 108 <?php get_template_part( 'template-parts/content', 'none' ); ?>
Note: See TracChangeset
for help on using the changeset viewer.