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 @@ + + + + + +