Templates: Add archive template for pledge list

This also uses the pledge list display for search results, which may need to be updated once case studies are full posts. Until then, the search results only returns pledges.
This commit is contained in:
Kelly Dwan 2024-08-29 14:49:21 -04:00
parent 16bbfbd817
commit 906a87588c
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D
3 changed files with 123 additions and 0 deletions

View file

@ -18,6 +18,7 @@ require_once __DIR__ . '/src/pledge-teams/index.php';
*/
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
add_filter( 'the_content', __NAMESPACE__ . '\inject_pledge_content' );
add_filter( 'search_template_hierarchy', __NAMESPACE__ . '\use_archive_template' );
/**
* Enqueue scripts and styles.
@ -58,4 +59,18 @@ function inject_pledge_content( $content ) {
$data = get_pledge_meta( get_the_ID() );
$content = apply_filters( 'the_content', $data['org-description'] );
return $content;
/**
* Switch to the archive.html template on search results.
*
* @param string[] $templates A list of template candidates, in descending order of priority.
*/
function use_archive_template( $templates ) {
global $wp_query;
if ( is_search() ) {
array_unshift( $templates, 'archive-5ftf_pledge.html' );
}
return $templates;
}

View file

@ -0,0 +1,97 @@
<?php
/**
* Title: Pledge List
* Slug: wporg-5ftf-2024/archive-5ftf-pledge
* Categories: wporg
*/
$page_title = __( 'Pledges', 'wporg-5ftf' );
if ( is_search() ) {
$page_title = __( 'Search results', 'wporg-5ftf' );
}
?>
<!-- wp:group {"align":"wide","layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"space-between"}} -->
<div class="wp-block-group alignwide">
<!-- wp:heading {"level":1,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}}}} -->
<h1 class="wp-block-heading" style="margin-top:0;margin-bottom:0"><?php echo esc_html( $page_title ); ?></h1>
<!-- /wp:heading -->
<!-- wp:buttons -->
<div class="wp-block-buttons">
<!-- wp:button -->
<div class="wp-block-button">
<a class="wp-block-button__link wp-element-button" href="<?php echo esc_url( home_url( '/for-organizations/' ) ); ?>"><?php esc_html_e( 'Pledge your company', 'wporg-5ftf' ); ?></a>
</div>
<!-- /wp:button -->
</div>
<!-- /wp:buttons -->
</div>
<!-- /wp:group -->
<!-- wp:query {"queryId":15,"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"taxQuery":null,"parents":[]},"tagName":"main","align":"wide"} -->
<main class="wp-block-query alignwide">
<!-- wp:group {"align":"wide","style":{"spacing":{"margin":{"bottom":"var:preset|spacing|40"}}},"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"space-between"}} -->
<div class="wp-block-group alignwide" style="margin-bottom:var(--wp--preset--spacing--40)">
<!-- wp:group {"layout":{"type":"flex","flexWrap":"wrap"}} -->
<div class="wp-block-group">
<!-- wp:search {"showLabel":false,"placeholder":"<?php esc_html_e( 'Search pledges', 'wporg-5ftf' ); ?>","width":100,"widthUnit":"%","buttonText":"<?php esc_html_e( 'Search', 'wporg-5ftf' ); ?>","buttonPosition":"button-inside","buttonUseIcon":true,"className":"is-style-secondary-search-control"} /-->
<!-- wp:wporg/query-total /-->
</div>
<!-- /wp:group -->
<!-- wp:group {"style":{"spacing":{"blockGap":"0"}},"layout":{"type":"flex","flexWrap":"nowrap"},"className":"wporg-query-filters"} -->
<div class="wp-block-group wporg-query-filters">
<!-- wp:wporg/query-filter {"key":"sort"} /-->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:post-template {"style":{"spacing":{"blockGap":"var:preset|spacing|60"}}} -->
<!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|70"}},"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group">
<!-- wp:group {"style":{"border":{"style":"solid","width":"1px","color":"#d9d9d9","radius":"2px"},"spacing":{"padding":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20","left":"var:preset|spacing|20","right":"var:preset|spacing|20"}}},"backgroundColor":"light-grey-2","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-border-color has-light-grey-2-background-color has-background" style="border-color:#d9d9d9;border-style:solid;border-width:1px;border-radius:2px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)">
<!-- wp:post-featured-image {"aspectRatio":"1","width":"275px","scale":"contain"} /-->
</div>
<!-- /wp:group -->
<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|10"}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:post-title {"isLink":true,"fontSize":"heading-3"} /-->
<!-- wp:paragraph -->
<p>Has pledged…</p>
<!-- /wp:paragraph -->
<!-- wp:post-excerpt {"moreText":"[MORE]","showMoreOnNewLine":false,"excerptLength":50} /-->
</div>
<!-- /wp:group -->
<!-- wp:paragraph -->
<p>small avatar list</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- /wp:post-template -->
<!-- wp:spacer {"height":"var:preset|spacing|40","style":{"spacing":{"margin":{"top":"var:preset|spacing|40"}}}} -->
<div style="margin-top:var(--wp--preset--spacing--40);height:0" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous {"label":"<?php esc_html_e( 'Previous', 'wporg-5ftf' ); ?>"} /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next {"label":"<?php esc_html_e( 'Next', 'wporg-5ftf' ); ?>"} /-->
<!-- /wp:query-pagination -->
</main>
<!-- /wp:query -->

View file

@ -0,0 +1,11 @@
<!-- wp:template-part {"slug":"header","className":"has-display-contents"} /-->
<!-- wp:group {"tagName":"main","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space"},"blockGap":"var:preset|spacing|40"}},"layout":{"type":"constrained"}} -->
<main class="wp-block-group" style="padding-right:var(--wp--preset--spacing--edge-space);padding-left:var(--wp--preset--spacing--edge-space)">
<!-- wp:pattern {"slug":"wporg-5ftf-2024/archive-5ftf-pledge"} /-->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer"} /-->