Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add breadcrumbs to all pages #217

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions source/wp-content/themes/wporg-showcase-2022/inc/block-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
add_action( 'pre_get_posts', __NAMESPACE__ . '\modify_query' );
add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' );
add_filter( 'render_block_core/query-title', __NAMESPACE__ . '\update_archive_title', 10, 3 );
add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\update_site_breadcrumbs' );

/**
* Update the query total label to reflect "sites" found.
Expand Down Expand Up @@ -329,3 +330,72 @@ function update_archive_title( $block_content, $block, $instance ) {
}
return $block_content;
}

/**
* Update the breadcrumbs to the current page.
*/
function update_site_breadcrumbs( $breadcrumbs ) {
// Build up the breadcrumbs from scratch.
$breadcrumbs = array(
array(
'url' => home_url(),
'title' => __( 'Home', 'wporg' ),
),
);

if ( is_page() || is_single() ) {
if ( is_page( 'thanks' ) ) {
// For thanks, we want to use the parent page title.
$breadcrumbs[] = array(
'url' => false,
'title' => get_the_title( get_post_parent() ),
);
} else {
$breadcrumbs[] = array(
'url' => false,
'title' => get_the_title(),
);
}
return $breadcrumbs;
}

if ( is_search() ) {
$breadcrumbs[] = array(
'url' => home_url( '/archives/' ),
'title' => __( 'All sites', 'wporg' ),
);
$breadcrumbs[] = array(
'url' => false,
'title' => __( 'Search results', 'wporg' ),
);
return $breadcrumbs;
}

// `is_home` matches the "posts page", the All Sites page.
// `is_archive` matches any core archive (category, date, etc).
if ( is_home() || is_archive() ) {
// Get the current applied filters (except search, handled above).
$term_names = get_applied_filter_list( false );
if ( empty( $term_names ) ) {
$breadcrumbs[] = array(
'url' => false,
'title' => __( 'All sites', 'wporg' ),
);
return $breadcrumbs;
}

$breadcrumbs[] = array(
'url' => home_url( '/archives/' ),
'title' => __( 'All sites', 'wporg' ),
);

$term_names = wp_list_pluck( $term_names, 'name' );
$breadcrumbs[] = array(
'url' => false,
// translators: %s list of terms used for filtering.
'title' => implode( ', ', $term_names ),
);
}

return $breadcrumbs;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Title: Local Nav
* Slug: wporg-showcase-2022/nav-dark
* Inserter: no
*
* This nav bar also has the site title, so it should be used on interior pages.
*/

?>
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"charcoal-1","style":{"position":{"type":"sticky"},"elements":{"link":{"color":{"text":"var:preset|color|white"},":hover":{"color":{"text":"var:preset|color|white"}}}}},"textColor":"white","fontSize":"small"} -->
<!-- wp:site-title {"level":0,"fontSize":"small"} /-->

<!-- wp:navigation {"menuSlug":"showcase","textColor":"white","backgroundColor":"charcoal-1","hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /-->
<!-- /wp:wporg/local-navigation-bar -->

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"18px","bottom":"18px","left":"var:preset|spacing|edge-space","right":"var:preset|spacing|edge-space"}},"elements":{"link":{"color":{"text":"var:preset|color|white"}}}},"backgroundColor":"charcoal-1","textColor":"white","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between"}} -->
<div class="wp-block-group alignfull has-white-color has-charcoal-1-background-color has-text-color has-background has-link-color" style="padding-top:18px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:18px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:wporg/site-breadcrumbs {"fontSize":"small"} /--></div>
<!-- /wp:group -->
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
*/

?>
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"charcoal-1","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"17px","bottom":"18px"}},"position":{"type":"sticky"},"elements":{"link":{"color":{"text":"var:preset|color|white"},":hover":{"color":{"text":"var:preset|color|white"}}}}},"textColor":"white","fontSize":"small"} -->
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"charcoal-1","style":{"position":{"type":"sticky"},"elements":{"link":{"color":{"text":"var:preset|color|white"},":hover":{"color":{"text":"var:preset|color|white"}}}}},"textColor":"white","fontSize":"small"} -->
<!-- wp:site-title {"level":0,"fontSize":"small"} /-->

<!-- wp:navigation {"menuSlug":"showcase","textColor":"white","backgroundColor":"charcoal-1","hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /-->
<!-- wp:navigation {"menuSlug":"showcase","textColor":"white","backgroundColor":"charcoal-1","hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /-->
<!-- /wp:wporg/local-navigation-bar -->

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"18px","bottom":"18px","left":"var:preset|spacing|edge-space","right":"var:preset|spacing|edge-space"}}},"backgroundColor":"white","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between"}} -->
<div class="wp-block-group alignfull has-white-background-color has-background" style="padding-top:18px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:18px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:wporg/site-breadcrumbs {"fontSize":"small"} /--></div>
<!-- /wp:group -->
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ a:where(:not(.wp-element-button)):focus-visible {
}
}

/* Breadcrumbs: Inherit the current color, to support using on dark background with white text. */
.wp-block-wporg-site-breadcrumbs .is-current-page {
color: inherit;
}

/* Update the background & text color on /thanks page. */
body.page-template-page-submit-confirmation .wp-site-blocks {
background: var(--wp--preset--color--charcoal-1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!-- wp:template-part {"slug":"header","className":"has-display-contents","tagName":"div"} /-->
<!-- wp:wporg/global-header {"backgroundColor":"charcoal-1","style":{"border":{"bottom":{"color":"var:preset|color|white-opacity-15","style":"solid","width":"1px"}}}} /-->

<!-- wp:pattern {"slug":"wporg-showcase-2022/nav-dark"} /-->

<!-- wp:group {"tagName":"main","style":{"spacing":{"blockGap":"0px","padding":{"left":"var:preset|spacing|edge-space","right":"var:preset|spacing|edge-space"}}},"layout":{"type":"constrained","wideSize":"1760px"}} -->
<main class="wp-block-group" style="padding-left:var(--wp--preset--spacing--edge-space);padding-right:var(--wp--preset--spacing--edge-space)">
Expand Down
Loading