Skip to content

Commit

Permalink
Block theme: Remove separate archive page, homepage should show lates…
Browse files Browse the repository at this point in the history
…t posts

This updates all instances of `/archives/`, and removes the custom grid for the front page. This also adds a filter to use the archive template for "paged" queries (`/page/2/`), so that the homepage layout only applies to the homepage.

See #677
  • Loading branch information
ryelle committed Apr 17, 2024
1 parent 164aa6f commit 196633b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
add_action( 'wp_head', __NAMESPACE__ . '\add_social_meta_tags', 5 );
add_filter( 'document_title_parts', __NAMESPACE__ . '\set_document_title' );
add_filter( 'body_class', __NAMESPACE__ . '\add_status_body_class' );
add_filter( 'frontpage_template_hierarchy', __NAMESPACE__ . '\use_archive_template_paged' );

add_action(
'init',
Expand Down Expand Up @@ -426,12 +427,12 @@ function user_has_flagged_pattern() {
* Redirect category and tag archives to their canonical URLs.
*
* This prevents double URLs for every category/tag, e.g.,
* `/archives/?pattern-categories=footer` and `/categories/footer/`.
* `/?pattern-categories=footer` and `/categories/footer/`.
*/
function redirect_term_archives() {
global $wp_query;
$terms = get_applied_filter_list( false );
// True on the `/tag/…` URLs, and false on `/archive/?tag…` URLs.
// True on the `/tag/…` URLs, and false on `/?tag…` URLs.
$is_term_archive = is_tag() || is_category() || is_tax();

// Don't redirect on favorites or author archives.
Expand Down Expand Up @@ -577,3 +578,15 @@ function add_status_body_class( $classes ) {
}
return $classes;
}

/**
* Switch to the archive.html template on paged requests.
*
* @param string[] $templates A list of template candidates, in descending order of priority.
*/
function use_archive_template_paged( $templates ) {
if ( is_paged() ) {
array_unshift( $templates, 'archive.html' );
}
return $templates;
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function get_filter_action_url() {
if ( is_page( 'favorites' ) || is_page( 'my-patterns' ) || is_author() ) {
return home_url( $wp->request );
}
return home_url( '/archives/' );
return home_url( '/' );
}

/**
Expand Down Expand Up @@ -384,7 +384,7 @@ function add_site_navigation_menus( $menus ) {
}
$all_link = array(
'label' => __( 'All', 'wporg-patterns' ),
'url' => is_page( 'favorites' ) || is_author() ? home_url( $wp->request ) : home_url( '/archives/' ),
'url' => is_page( 'favorites' ) || is_author() ? home_url( $wp->request ) : home_url( '/' ),
'className' => empty( $current_cats ) ? 'current-menu-item' : '',
);
array_unshift( $categories, $all_link );
Expand Down Expand Up @@ -473,12 +473,7 @@ function update_site_breadcrumbs( $breadcrumbs ) {
$term_names = get_applied_filter_list( false );

// Build up the breadcrumbs from scratch.
$breadcrumbs = array(
array(
'url' => home_url(),
'title' => __( 'Home', 'wporg-patterns' ),
),
);
$breadcrumbs = array();

if ( is_page() || is_single() ) {
$breadcrumbs[] = array(
Expand All @@ -505,7 +500,7 @@ function update_site_breadcrumbs( $breadcrumbs ) {

if ( is_search() ) {
$breadcrumbs[] = array(
'url' => home_url( '/archives/' ),
'url' => home_url( '/' ),
'title' => __( 'All patterns', 'wporg-patterns' ),
);
$breadcrumbs[] = array(
Expand All @@ -521,7 +516,7 @@ function update_site_breadcrumbs( $breadcrumbs ) {
$author = isset( $wp_query->query['author_name'] ) ? get_user_by( 'slug', $wp_query->query['author_name'] ) : false;

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

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">
<?php printf(
/* translators: %s is url of the pattern archives. */
/* translators: %s is url of the homepage. */
wp_kses_post( __( 'View <a href="%s">all patterns</a> or try a different search. ', 'wporg-patterns' ) ),
esc_url( home_url( '/archives/' ) )
esc_url( home_url( '/' ) )
); ?>
</p>
<!-- /wp:paragraph -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ body.page .wp-block-wporg-local-navigation-bar .wp-block-query-title {
display: none;
}

/* Hide the grid `h1` on the homepage, as the header has an h1. */
body.blog:not(.paged) .wp-block-query .wp-block-query-title {
display: none;
}

/*
* A linked post title should be blueberry (needed to override parent setting,
* where post title is the same for linked or not).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
</main>
<!-- /wp:group -->

<!-- wp:template-part {"slug":"footer"} /-->
<!-- wp:template-part {"slug":"footer"} /-->
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"},"className":"entry-content","style":{"spacing":{"blockGap":"0px"}}} -->
<main class="wp-block-group entry-content">

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull" style="padding-right:var(--wp--preset--spacing--edge-space);padding-left:var(--wp--preset--spacing--edge-space)">
<!-- wp:pattern {"slug":"wporg-pattern-directory-2024/grid-front-page"} /-->
<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"left":"var:preset|spacing|edge-space","right":"var:preset|spacing|edge-space","bottom":"var:preset|spacing|40"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull" style="padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--edge-space)">
<!-- wp:pattern {"slug":"wporg-pattern-directory-2024/grid"} /-->
</div>
<!-- /wp:group -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
</main>
<!-- /wp:group -->

<!-- wp:template-part {"slug":"footer"} /-->
<!-- wp:template-part {"slug":"footer"} /-->

0 comments on commit 196633b

Please sign in to comment.