Open nabi009 opened 3 years ago
` /**
const { } = wp.i18n; // Import () from wp.i18n const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks const { PlainText, RichText, InspectorControls } = wp.editor; const { Fragment } = wp.element; const { TextControl, ToggleControl, Panel, PanelBody, PanelRow, SelectControl, Dropdown, Button, CheckboxControl } = wp.components; /**
registered; otherwise undefined. */ registerBlockType( 'cgb/block-nh-blocks', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. title: ( 'nh-blocks - Latest Block' ), // Block title. icon: 'shield', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. category: 'text', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. keywords: [ ( 'nh-blocks — Post Block' ), ( 'Posts by Category' ), ( 'create-guten-block' ), ],
undefined
attributes: { categories: { type: 'array' }, selectCategory: { type: 'string' },
}, /**
@returns {Mixed} JSX Component. */ edit: ( props ) => { // Creates a
return (
<InspectorControls> <PanelBody> <PanelRow> <label>Set Filter</label> </PanelRow> <PanelRow> <categories /> </PanelRow> </PanelBody> </InspectorControls>
); },
/**
`
const { Component } = wp.element;
export class categories extends Component { constructor( props ) { super( ...arguments ); this.props = props; }
render() { return ( <p>categories label</p> ); }
}
` /**
const { } = wp.i18n; // Import () from wp.i18n const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks const { PlainText, RichText, InspectorControls } = wp.editor; const { Fragment } = wp.element; const { TextControl, ToggleControl, Panel, PanelBody, PanelRow, SelectControl, Dropdown, Button, CheckboxControl } = wp.components; /**
registered; otherwise
undefined
. */ registerBlockType( 'cgb/block-nh-blocks', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. title: ( 'nh-blocks - Latest Block' ), // Block title. icon: 'shield', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. category: 'text', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. keywords: [ ( 'nh-blocks — Post Block' ), ( 'Posts by Category' ), ( 'create-guten-block' ), ],attributes: { categories: { type: 'array' }, selectCategory: { type: 'string' },
}, /**
@returns {Mixed} JSX Component. */ edit: ( props ) => { // Creates a
. if ( ! props.attributes.categories ) { wp.apiFetch( { url: '/wp-json/wp/v2/categories', } ).then( categories => { props.setAttributes( { categories: categories } ); } ); } console.log( props.attributes.categories );return (
); },
/**
`
`
const { Component } = wp.element;
export class categories extends Component { constructor( props ) { super( ...arguments ); this.props = props; }
}
`