From c664b539e7739eb1e2baf45b8164ec19129b74e8 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 27 Jun 2017 13:36:51 +0200 Subject: [PATCH] First pass at archives block --- blocks/library/archives/index.js | 58 +++++++++++++++++++++ blocks/library/index.js | 1 + gutenberg.php | 1 + lib/blocks/archives.php | 88 ++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 blocks/library/archives/index.js create mode 100644 lib/blocks/archives.php diff --git a/blocks/library/archives/index.js b/blocks/library/archives/index.js new file mode 100644 index 0000000000000..c432efd4071c8 --- /dev/null +++ b/blocks/library/archives/index.js @@ -0,0 +1,58 @@ +/** + * WordPress dependencies + */ +import { Component } from 'element'; +import { Placeholder } from 'components'; +import { __ } from 'i18n'; + +/** + * Internal dependencies + */ +import { registerBlockType } from '../../api'; +import InspectorControls from '../../inspector-controls'; +import ToggleControl from '../../inspector-controls/toggle-control'; + +registerBlockType( 'core/archives', { + title: __( 'Archives' ), + + icon: 'calendar-alt', + + category: 'widgets', + + defaultAttributes: { + count: true, + dropdown: false, + }, + + edit( { attributes, setAttributes, focus } ) { + const { count, dropdown } = attributes; + const toggleCount = () => setAttributes( { count: ! count } ); + const toggleDropdown = () => setAttributes( { dropdown: ! dropdown } ); + return [ + focus && ( + + + + + ), + + , + ]; + }, + + save() { + return null; + }, +} ); diff --git a/blocks/library/index.js b/blocks/library/index.js index 93a71f0cc3acc..bdc2897577201 100644 --- a/blocks/library/index.js +++ b/blocks/library/index.js @@ -15,3 +15,4 @@ import './html'; import './freeform'; import './latest-posts'; import './cover-image'; +import './archives'; diff --git a/gutenberg.php b/gutenberg.php index 97ec81112800d..9a7d589e6a8a6 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -23,4 +23,5 @@ // Register server-side code for individual blocks. require_once dirname( __FILE__ ) . '/lib/blocks/latest-posts.php'; + require_once dirname( __FILE__ ) . '/lib/blocks/archives.php'; } diff --git a/lib/blocks/archives.php b/lib/blocks/archives.php new file mode 100644 index 0000000000000..870cb86d309ea --- /dev/null +++ b/lib/blocks/archives.php @@ -0,0 +1,88 @@ + 'monthly', + 'format' => 'option', + 'show_post_count' => $count, + ) ); + + $dropdown_args['echo'] = 0; + + $archives = wp_get_archives( $dropdown_args ); + + switch ( $dropdown_args['type'] ) { + case 'yearly': + $label = __( 'Select Year' ); + break; + case 'monthly': + $label = __( 'Select Month' ); + break; + case 'daily': + $label = __( 'Select Day' ); + break; + case 'weekly': + $label = __( 'Select Week' ); + break; + default: + $label = __( 'Select Post' ); + break; + } + + $label = esc_attr( $label ); + + $block_content = << + +