From 8a28466bb278b53cb1212995f6020e7dcf94d28c Mon Sep 17 00:00:00 2001 From: Ren <18050944+renintw@users.noreply.github.com> Date: Mon, 8 Jul 2024 12:14:18 +0800 Subject: [PATCH] Align local nav and add breadcrumbs for pages (#2598) * Add local navigation for different scenarios - L3, L2A, L2B, L1A, learning pathways term, tax search page, and course search page * add various header template parts * remove the extra group block that wraps the site breadcrumbs * Add "page" breadcrumbs * Ensure breadcrumbs are displayed only when there are at least 3 levels. * Update breadcrumbs padding top/btm to 18px --- .../themes/pub/wporg-learn-2024/functions.php | 27 +++++++++++++++-- .../pub/wporg-learn-2024/inc/block-hooks.php | 29 +++++++++++++++++++ .../parts/header-second-archive-title.html | 18 ++++++++++++ .../parts/header-second-post-title.html | 18 ++++++++++++ .../wporg-learn-2024/parts/header-second.html | 17 +++++++++++ .../parts/header-third-archive-title.html | 20 +++++++++++++ .../parts/header-third-post-title.html | 20 +++++++++++++ .../pub/wporg-learn-2024/parts/header.html | 6 +--- .../patterns/sensei-lesson-header.php | 6 +--- .../templates/archive-course.html | 2 +- .../templates/archive-lesson-plan.html | 2 +- .../templates/archive-lesson.html | 2 +- .../wporg-learn-2024/templates/archive.html | 2 +- .../templates/page-apply-to-facilitate.html | 2 +- .../templates/page-contribute.html | 8 +---- .../templates/page-course-complete.html | 2 +- .../templates/page-learning-pathways.html | 2 +- .../templates/page-my-courses.html | 2 +- .../templates/page-online-workshops.html | 2 +- .../pub/wporg-learn-2024/templates/page.html | 4 ++- .../templates/single-course.html | 9 +----- .../templates/single-wporg_workshop.html | 8 +---- .../wporg-learn-2024/templates/single.html | 2 +- .../templates/taxonomy-learning-pathway.html | 2 +- .../wporg-learn-2024/templates/taxonomy.html | 2 +- 25 files changed, 167 insertions(+), 47 deletions(-) create mode 100644 wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php create mode 100644 wp-content/themes/pub/wporg-learn-2024/parts/header-second-archive-title.html create mode 100644 wp-content/themes/pub/wporg-learn-2024/parts/header-second-post-title.html create mode 100644 wp-content/themes/pub/wporg-learn-2024/parts/header-second.html create mode 100644 wp-content/themes/pub/wporg-learn-2024/parts/header-third-archive-title.html create mode 100644 wp-content/themes/pub/wporg-learn-2024/parts/header-third-post-title.html diff --git a/wp-content/themes/pub/wporg-learn-2024/functions.php b/wp-content/themes/pub/wporg-learn-2024/functions.php index 54a6cd3ae..2d4b7c1a3 100644 --- a/wp-content/themes/pub/wporg-learn-2024/functions.php +++ b/wp-content/themes/pub/wporg-learn-2024/functions.php @@ -14,6 +14,7 @@ require_once __DIR__ . '/src/upcoming-online-workshops/index.php'; require_once __DIR__ . '/src/sensei-meta-list/index.php'; require_once __DIR__ . '/inc/block-config.php'; +require_once __DIR__ . '/inc/block-hooks.php'; require_once __DIR__ . '/inc/query.php'; /** @@ -221,9 +222,9 @@ function get_learning_pathway_level_content( $learning_pathway ) { /** * Filters breadcrumb items for the site-breadcrumb block. * - * @param array $breadcrumbs + * @param array $breadcrumbs The current breadcrumbs. * - * @return array + * @return array The modified breadcrumbs. */ function set_site_breadcrumbs( $breadcrumbs ) { if ( isset( $breadcrumbs[0] ) ) { @@ -274,6 +275,28 @@ function set_site_breadcrumbs( $breadcrumbs ) { $breadcrumbs[1] = $archive_breadcrumb; array_splice( $breadcrumbs, 2, 0, array( $lesson_course_breadcrumb ) ); } + } else { + // Add the ancestors of the current page to the breadcrumbs. + $ancestors = get_post_ancestors( get_the_ID() ); + + if ( ! empty( $ancestors ) ) { + foreach ( $ancestors as $ancestor ) { + $ancestor_post = get_post( $ancestor ); + + $ancestor_breadcrumb = array( + 'url' => get_permalink( $ancestor_post ), + 'title' => get_the_title( $ancestor_post ), + ); + + array_splice( $breadcrumbs, 1, 0, array( $ancestor_breadcrumb ) ); + } + } + } + + // Ensure breadcrumbs are displayed only when there are at least 3 levels. + $breadcrumb_level = count( $breadcrumbs ); + if ( $breadcrumb_level < 3 ) { + $breadcrumbs = array(); } return $breadcrumbs; diff --git a/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php b/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php new file mode 100644 index 000000000..223dc4b26 --- /dev/null +++ b/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php @@ -0,0 +1,29 @@ + + + + + +
+ + +
+ + + + + + + +
+ diff --git a/wp-content/themes/pub/wporg-learn-2024/parts/header-second-post-title.html b/wp-content/themes/pub/wporg-learn-2024/parts/header-second-post-title.html new file mode 100644 index 000000000..bfc11b65f --- /dev/null +++ b/wp-content/themes/pub/wporg-learn-2024/parts/header-second-post-title.html @@ -0,0 +1,18 @@ + + + + + +
+ + +
+ + + + + + + +
+ diff --git a/wp-content/themes/pub/wporg-learn-2024/parts/header-second.html b/wp-content/themes/pub/wporg-learn-2024/parts/header-second.html new file mode 100644 index 000000000..02040da00 --- /dev/null +++ b/wp-content/themes/pub/wporg-learn-2024/parts/header-second.html @@ -0,0 +1,17 @@ + + + + + +
+ +
+ + + + + + + +
+ diff --git a/wp-content/themes/pub/wporg-learn-2024/parts/header-third-archive-title.html b/wp-content/themes/pub/wporg-learn-2024/parts/header-third-archive-title.html new file mode 100644 index 000000000..96c3d0ae5 --- /dev/null +++ b/wp-content/themes/pub/wporg-learn-2024/parts/header-third-archive-title.html @@ -0,0 +1,20 @@ + + + + + +
+ + +
+ + + + + + + +
+ + + diff --git a/wp-content/themes/pub/wporg-learn-2024/parts/header-third-post-title.html b/wp-content/themes/pub/wporg-learn-2024/parts/header-third-post-title.html new file mode 100644 index 000000000..96231a0c4 --- /dev/null +++ b/wp-content/themes/pub/wporg-learn-2024/parts/header-third-post-title.html @@ -0,0 +1,20 @@ + + + + + +
+ + +
+ + + + + + + +
+ + + diff --git a/wp-content/themes/pub/wporg-learn-2024/parts/header.html b/wp-content/themes/pub/wporg-learn-2024/parts/header.html index 5eeff5046..02040da00 100644 --- a/wp-content/themes/pub/wporg-learn-2024/parts/header.html +++ b/wp-content/themes/pub/wporg-learn-2024/parts/header.html @@ -1,14 +1,10 @@ - +
- - - -
diff --git a/wp-content/themes/pub/wporg-learn-2024/patterns/sensei-lesson-header.php b/wp-content/themes/pub/wporg-learn-2024/patterns/sensei-lesson-header.php index f36d3b52f..21f27b5c6 100644 --- a/wp-content/themes/pub/wporg-learn-2024/patterns/sensei-lesson-header.php +++ b/wp-content/themes/pub/wporg-learn-2024/patterns/sensei-lesson-header.php @@ -15,11 +15,7 @@
- -
- -
- +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/archive-course.html b/wp-content/themes/pub/wporg-learn-2024/templates/archive-course.html index 906938012..edc47f2f4 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/archive-course.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/archive-course.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson-plan.html b/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson-plan.html index 98e08d78e..6196b93e8 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson-plan.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson-plan.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson.html b/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson.html index 7869d15ad..a15a52b08 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/archive-lesson.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/archive.html b/wp-content/themes/pub/wporg-learn-2024/templates/archive.html index 3a6ada30d..45e403161 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/archive.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/archive.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/page-apply-to-facilitate.html b/wp-content/themes/pub/wporg-learn-2024/templates/page-apply-to-facilitate.html index 550f045c7..f600e6524 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/page-apply-to-facilitate.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/page-apply-to-facilitate.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/page-contribute.html b/wp-content/themes/pub/wporg-learn-2024/templates/page-contribute.html index 6956dd5db..d01b09271 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/page-contribute.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/page-contribute.html @@ -1,10 +1,4 @@ - - - -
- -
- +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/page-course-complete.html b/wp-content/themes/pub/wporg-learn-2024/templates/page-course-complete.html index 7f65d75f5..ed632c0ab 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/page-course-complete.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/page-course-complete.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/page-learning-pathways.html b/wp-content/themes/pub/wporg-learn-2024/templates/page-learning-pathways.html index 41ad1c4d2..1d120b865 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/page-learning-pathways.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/page-learning-pathways.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/page-my-courses.html b/wp-content/themes/pub/wporg-learn-2024/templates/page-my-courses.html index 30bb817d2..2302255fb 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/page-my-courses.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/page-my-courses.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/page-online-workshops.html b/wp-content/themes/pub/wporg-learn-2024/templates/page-online-workshops.html index 8aa4b6886..99192ff97 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/page-online-workshops.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/page-online-workshops.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/page.html b/wp-content/themes/pub/wporg-learn-2024/templates/page.html index 24c46d2a4..a6ef2f761 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/page.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/page.html @@ -1,4 +1,6 @@ - + + +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/single-course.html b/wp-content/themes/pub/wporg-learn-2024/templates/single-course.html index f90bb7288..508ce130a 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/single-course.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/single-course.html @@ -1,11 +1,4 @@ - - - -
- -
- - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/single-wporg_workshop.html b/wp-content/themes/pub/wporg-learn-2024/templates/single-wporg_workshop.html index 4dff02adb..bf4fcded2 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/single-wporg_workshop.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/single-wporg_workshop.html @@ -1,10 +1,4 @@ - - - -
- -
- +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/single.html b/wp-content/themes/pub/wporg-learn-2024/templates/single.html index aabcf8f06..61e48e449 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/single.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/single.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy-learning-pathway.html b/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy-learning-pathway.html index 9bd9a4b5a..7bd7647f3 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy-learning-pathway.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy-learning-pathway.html @@ -1,4 +1,4 @@ - +
diff --git a/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy.html b/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy.html index b97344eae..485a02f7a 100644 --- a/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy.html +++ b/wp-content/themes/pub/wporg-learn-2024/templates/taxonomy.html @@ -1,4 +1,4 @@ - +