-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try using a php block that queries. Example query filtering. add block build script. Add the patterns Hook in another filter. Rename template. Some minor updates. Add the month filter
- Loading branch information
1 parent
70eaf22
commit 16b2f50
Showing
11 changed files
with
389 additions
and
0 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
26 changes: 26 additions & 0 deletions
26
public_html/wp-content/themes/wporg-events-2023/patterns/events-list-filters.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,26 @@ | ||
<?php | ||
/** | ||
* Title: Events List Filters | ||
* Slug: wporg-events-2023/event-list-filters | ||
* Inserter: no | ||
*/ | ||
|
||
?> | ||
|
||
<!-- wp:group {"align":"wide","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between"}} --> | ||
<div class="wp-block-group alignwide"> | ||
<!-- wp:group {"layout":{"type":"flex","flexWrap":"wrap"}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:search {"showLabel":false,"placeholder":"<?php esc_html_e( 'Search events...', 'wporg' ); ?>","width":100,"widthUnit":"%","buttonText":"<?php esc_html_e( 'Search', 'wporg' ); ?>","buttonPosition":"button-inside","buttonUseIcon":true,"className":"is-style-secondary-search-control"} /--> | ||
</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":"format_type","multiple":false} /--> | ||
<!-- wp:wporg/query-filter {"key":"event_type","multiple":false} /--> | ||
<!-- wp:wporg/query-filter {"key":"month","multiple":false} /--> | ||
</div> | ||
<!-- /wp:group --> | ||
</div> | ||
<!-- /wp:group --> |
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
29 changes: 29 additions & 0 deletions
29
public_html/wp-content/themes/wporg-events-2023/src/event-list/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,29 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "wporg/event-list", | ||
"version": "0.1.0", | ||
"title": "WordPress Events List", | ||
"category": "design", | ||
"icon": "list-view", | ||
"description": "List of WordPress Events", | ||
"textdomain": "wporg", | ||
"supports": { | ||
"align": true, | ||
"color": { | ||
"background": true, | ||
"text": true | ||
}, | ||
"spacing": { | ||
"margin": [ "top", "bottom" ], | ||
"padding": true, | ||
"blockGap": false | ||
}, | ||
"typography": { | ||
"fontSize": true, | ||
"lineHeight": true | ||
} | ||
}, | ||
"editorScript": "file:./index.js", | ||
"style": "file:./style-index.css" | ||
} |
20 changes: 20 additions & 0 deletions
20
public_html/wp-content/themes/wporg-events-2023/src/event-list/edit.js
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,20 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
||
import { Disabled } from '@wordpress/components'; | ||
import ServerSideRender from '@wordpress/server-side-render'; | ||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
export default function Edit( { attributes, name } ) { | ||
return ( | ||
<div { ...useBlockProps() }> | ||
<InspectorControls> | ||
|
||
</InspectorControls> | ||
<Disabled> | ||
<ServerSideRender block={ name } attributes={ attributes } /> | ||
</Disabled> | ||
</div> | ||
); | ||
} |
16 changes: 16 additions & 0 deletions
16
public_html/wp-content/themes/wporg-events-2023/src/event-list/index.js
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 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Edit from './edit'; | ||
import metadata from './block.json'; | ||
import './style.scss'; | ||
|
||
registerBlockType( metadata.name, { | ||
edit: Edit, | ||
save: () => null, | ||
} ); |
119 changes: 119 additions & 0 deletions
119
public_html/wp-content/themes/wporg-events-2023/src/event-list/index.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,119 @@ | ||
<?php | ||
/** | ||
* Block Name: WordPress Event List | ||
* Description: List of WordPress Events. | ||
* | ||
* @package wporg | ||
*/ | ||
|
||
namespace WordPressdotorg\Theme\Events_2023\WordPress_Event_List; | ||
|
||
use function WordPressdotorg\MU_Plugins\Google_Map\{get_all_upcoming_events}; | ||
|
||
add_action( 'init', __NAMESPACE__ . '\init' ); | ||
|
||
/** | ||
* Registers the block using the metadata loaded from the `block.json` file. | ||
* Behind the scenes, it registers also all assets so they can be enqueued | ||
* through the block editor in the corresponding context. | ||
* | ||
* @see https://developer.wordpress.org/reference/functions/register_block_type/ | ||
*/ | ||
function init() { | ||
register_block_type( | ||
dirname( dirname( __DIR__ ) ) . '/build/event-list', | ||
array( | ||
'render_callback' => __NAMESPACE__ . '\render', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Render the block content. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block default content. | ||
* @param WP_Block $block Block instance. | ||
* | ||
* @return string Returns the block markup. | ||
*/ | ||
function render( $attributes, $content, $block ) { | ||
|
||
// Get all the events | ||
$events = get_event_list(); | ||
|
||
// Get all the filters that are currently applied. | ||
$filtered_events = array_slice( filter_events( $events ), 0, 10); | ||
|
||
// loop through events output markup using gutenberg blocks | ||
$content = '<ul class="wporg-marker-list__container">'; | ||
|
||
foreach ( $filtered_events as $event ) { | ||
$content .= '<li class="wporg-marker-list-item">'; | ||
$content .= '<h3 class="wporg-marker-list-item__title">' . $event->title . '</h3>'; | ||
$content .= '<div class="wporg-marker-list-item__location">' . $event->location . '</div>'; | ||
$content .= '<div class="wporg-marker-list-item__date-time">' . $event->timestamp . '</div>'; | ||
$content .= '</li>'; | ||
} | ||
|
||
$content .= '</ul>'; | ||
|
||
$wrapper_attributes = get_block_wrapper_attributes(); | ||
return sprintf( | ||
'<div %1$s>%2$s</div>', | ||
$wrapper_attributes, | ||
do_blocks( $content ) | ||
); | ||
} | ||
|
||
/** | ||
* Get a list of the currently-applied filters. | ||
* | ||
* @param boolean $include_search Whether the result should include the search term. | ||
* | ||
* @return array | ||
*/ | ||
function filter_events( $events ) { | ||
global $wp_query; | ||
|
||
$taxes = array( | ||
'map_type' => 'map_type', | ||
); | ||
$terms = array(); | ||
|
||
// Get the terms | ||
foreach ( $taxes as $query_var => $taxonomy ) { | ||
|
||
if ( ! isset( $wp_query->query[ $query_var ] ) ) { | ||
continue; | ||
} | ||
|
||
$values = (array) $wp_query->query[ $query_var ]; | ||
foreach ( $values as $value ) { | ||
$terms[] = $value; | ||
} | ||
} | ||
|
||
if ( empty( $terms ) ) { | ||
return $events; | ||
} | ||
|
||
$filtered_events = array(); | ||
foreach ( $events as $event ) { | ||
// Assuming each event has a 'type' property | ||
if ( isset($event->type) && in_array($event->type, $terms) ) { | ||
$filtered_events[] = $event; | ||
} | ||
} | ||
|
||
return $filtered_events; | ||
} | ||
|
||
/** | ||
* Retrieves event list based on the filters. | ||
* | ||
* @return array | ||
*/ | ||
function get_event_list(): array { | ||
return get_all_upcoming_events(); | ||
} |
Empty file.
15 changes: 15 additions & 0 deletions
15
public_html/wp-content/themes/wporg-events-2023/templates/page-upcoming.html
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,15 @@ | ||
<!-- wp:template-part {"slug":"header"} /--> | ||
|
||
<!-- wp:group {"tagName":"main","style":{"spacing":{"blockGap":"0px"}},"className":"entry-content","layout":{"type":"constrained"}} --> | ||
<main class="wp-block-group entry-content"> | ||
<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"var:preset|spacing|40","left":"var:preset|spacing|edge-space","right":"var:preset|spacing|edge-space","bottom":"var:preset|spacing|40"}}},"layout":{"type":"default"}} --> | ||
<div class="wp-block-group alignfull" style="padding-top:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--edge-space);padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:var(--wp--preset--spacing--40)"> | ||
<!-- wp:post-title /--> | ||
<!-- wp:pattern {"slug":"wporg-events-2023/event-list-filters"} /--> | ||
<!-- wp:wporg/event-list /--> | ||
</div> | ||
<!-- /wp:group --> | ||
</main> | ||
<!-- /wp:group --> | ||
|
||
<!-- wp:template-part {"slug":"footer"} /--> |
Oops, something went wrong.