forked from amnestywebsite/humanity-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace searchpage.php with FSE template
Many props to @Gentyspun
- Loading branch information
Showing
12 changed files
with
226 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
wp-content/themes/humanity-theme/includes/full-site-editing/blocks/search-header/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/WordPress/gutenberg/trunk/schemas/json/block.json", | ||
"apiVersion": 2, | ||
"name": "amnesty-core/search-header", | ||
"title": "Search Header", | ||
"description": "For presenting the search page header", | ||
"textdomain": "amnesty", | ||
"category": "amnesty-core", | ||
"icon": "editor-table", | ||
"keywords": ["Search Header"], | ||
"usesContext": [], | ||
"supports": { | ||
"multiple": false, | ||
"align": false | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ontent/themes/humanity-theme/includes/full-site-editing/blocks/search-header/register.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare( strict_types = 1 ); | ||
|
||
if ( ! function_exists( 'register_search_header_block' ) ) { | ||
/** | ||
* Register the search header block | ||
* | ||
* @package Amnesty\Blocks | ||
* | ||
* @return void | ||
*/ | ||
function register_search_header_block(): void { | ||
register_block_type_from_metadata( | ||
__DIR__, | ||
[ | ||
'render_callback' => 'render_search_header_block', | ||
], | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
wp-content/themes/humanity-theme/includes/full-site-editing/blocks/search-header/render.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare( strict_types = 1 ); | ||
|
||
if ( ! function_exists( 'render_search_header_block' ) ) { | ||
/** | ||
* Render the post search header block | ||
* | ||
* @return string | ||
*/ | ||
function render_search_header_block(): string { | ||
spaceless(); | ||
|
||
get_template_part( 'partials/archive/header' ); | ||
|
||
return endspaceless( false ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* Title: Search pattern | ||
* Description: Search pattern for the theme | ||
* Slug: amnesty/search | ||
* Inserter: no | ||
*/ | ||
|
||
$location_slug = get_option( 'amnesty_location_slug' ) ?: 'location'; | ||
$search_object = amnesty_get_searchpage_query_object( false ); | ||
$order_vars = $search_object->get_order_vars(); | ||
|
||
$args = [ | ||
'inherit' => false, | ||
'query' => [ | ||
'perPage' => null, | ||
'pages' => 0, | ||
'offset' => 0, | ||
'postType' => apply_filters( 'amnesty_list_query_post_types', [ 'page', 'post' ] ), | ||
'order' => $order_vars['order'], | ||
'orderby' => $order_vars['orderby'], | ||
'author' => '', | ||
'search' => '', // if there's a term, we'll be on a different template | ||
'exclude' => [], // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude | ||
'sticky' => false, | ||
'taxQuery' => $search_object->build_tax_args(), | ||
'parents' => [], | ||
], | ||
]; | ||
|
||
add_filter( 'query_loop_block_query_vars', fn () => $args['query'] ); | ||
|
||
if ( amnesty_get_query_var( 'qyear' ) ) { | ||
add_filter( 'query_loop_block_query_vars', fn ( array $vars ): array => $vars + [ 'year' => amnesty_get_query_var( 'qyear' ) ] ); | ||
} | ||
|
||
if ( amnesty_get_query_var( 'qmonth' ) ) { | ||
add_filter( 'query_loop_block_query_vars', fn ( array $vars ): array => $vars + [ 'monthnum' => amnesty_get_query_var( 'qmonth' ) ] ); | ||
} | ||
|
||
|
||
// add filter to limit the post terms results for search | ||
add_filter( 'get_the_terms', 'amnesty_limit_post_terms_results_for_search' ); | ||
|
||
?> | ||
|
||
<!-- wp:query <?php echo wp_kses_data( wp_json_encode( $args ) ); ?> --> | ||
<div class="wp-block-query"> | ||
<!-- wp:group {"tagName":"div","className":"section section--tinted search-results"} --> | ||
<div class="wp-block-group section section--tinted search-results"> | ||
<!-- wp:amnesty-core/search-header /--> | ||
<!-- wp:post-template {"layout":{"type":"constrained","justifyContent":"left"}} --> | ||
|
||
<!-- wp:group {"tagName":"article","className":"post post--result"} --> | ||
<article class="wp-block-group post post--result"> | ||
<!-- wp:group {"tagName":"div","className":"post-terms","layout":{"type":"flex","flexWrap":"nowrap"}} --> | ||
<div class="wp-block-group post-terms"> | ||
<!-- wp:post-terms {"term":"category","className":"post-category"} /--> | ||
<!-- wp:post-terms {"term":"<?php echo esc_attr( $location_slug ); ?>","className":"post-location"} /--> | ||
<!-- wp:post-terms {"term":"topic","className":"post-topic"} /--> | ||
</div> | ||
<!-- /wp:group --> | ||
<!-- wp:post-title {"isLink":true,"className":"post-title"} /--> | ||
<!-- wp:post-excerpt {"className":"post-excerpt"} /--> | ||
<!-- wp:post-date {"className":"post-byline"} /--> | ||
</article> | ||
<!-- /wp:group --> | ||
|
||
<!-- /wp:post-template --> | ||
</div> | ||
<!-- /wp:group --> | ||
|
||
<!-- wp:query-pagination {"align":"center","className":"section section--small","paginationArrow":"none","layout":{"type":"flex","justifyContent":"space-between","flexWrap":"nowrap"}} --> | ||
<!-- wp:query-pagination-previous {"label":"Previous"} /--> | ||
<!-- wp:query-pagination-numbers {"midSize":1,"className":"page-numbers"} /--> | ||
<!-- wp:query-pagination-next {"label":"Next"} /--> | ||
<!-- /wp:query-pagination --> | ||
</div> | ||
<!-- /wp:query --> |
Oops, something went wrong.