'sidebar-list',
'sidebar-numbered' => 'sidebar-numbered',
'sidebar-large' => 'sidebar-large',
);
return $types;
}
/**
* Get name of layout by key.
*
* @param mixed $key The key.
*/
public function get_name_of_layout_by( $key ) {
switch ( $key ) {
case 'sidebar-list':
return esc_html__( 'Widget 1', 'canvas' );
case 'sidebar-numbered':
return esc_html__( 'Widget 2', 'canvas' );
case 'sidebar-large':
return esc_html__( 'Widget 3', 'canvas' );
}
}
/**
* Get icon of layout by key.
*
* @param mixed $key The key.
*/
public function get_icon_of_layout_by( $key ) {
switch ( $key ) {
case 'sidebar-list':
return '';
case 'sidebar-numbered':
return '';
case 'sidebar-large':
return '';
}
}
/**
* Register layout.
*
* @param array $layouts List of layouts.
*/
public function register_layout( $layouts = array() ) {
$types = $this->get_types_of_layouts();
foreach ( $types as $type ) {
$layouts[ $type ] = array(
'location' => array( 'section-sidebar' ),
'name' => $this->get_name_of_layout_by( $type ),
'template' => dirname( __FILE__ ) . '/block-posts-sidebar/layouts/posts-sidebar.php',
'icon' => $this->get_icon_of_layout_by( $type ),
'sections' => array(
'general' => array(
'title' => esc_html__( 'Block Settings', 'canvas' ),
'priority' => 5,
'open' => true,
),
),
'hide_fields' => array(
'postsCount',
'showExcerpt',
'showViewPostButton',
'showPagination',
'colorText',
'colorHeading',
'colorHeadingHover',
'colorText',
'colorMeta',
'colorMetaHover',
'colorMetaLinks',
'colorMetaLinksHover',
),
'fields' => array(
array(
'key' => 'widgetPostsCount',
'label' => esc_html__( 'Posts Count', 'canvas' ),
'section' => 'pagination',
'type' => 'number',
'default' => 5,
'min' => 1,
'max' => 100,
),
// Color Settings.
array(
'key' => 'colorHeading',
'label' => esc_html__( 'Heading', 'canvas' ),
'section' => 'color',
'type' => 'color',
'default' => '#000',
'output' => array(
array(
'element' => '$.cnvs-block-posts-sidebar .entry-title a',
'property' => 'color',
),
),
),
array(
'key' => 'colorHeadingHover',
'label' => esc_html__( 'Heading Hover', 'canvas' ),
'section' => 'color',
'type' => 'color',
'default' => '#5a5a5a',
'output' => array(
array(
'element' => '$.cnvs-block-posts-sidebar .entry-title a:hover, $.cnvs-block-posts-sidebar .entry-title a:focus',
'property' => 'color',
),
),
),
array(
'key' => 'colorMetaLinks',
'label' => esc_html__( 'Post Meta Links', 'canvas' ),
'section' => 'color',
'type' => 'color',
'default' => '',
'output' => array(
array(
'element' => '$.cnvs-block-posts-sidebar .cnvs-post-meta a, $.cnvs-block-posts-sidebar .post-categories a',
'property' => 'color',
),
),
),
array(
'key' => 'colorMetaLinksHover',
'label' => esc_html__( 'Post Meta Links Hover', 'canvas' ),
'section' => 'color',
'type' => 'color',
'default' => '',
'output' => array(
array(
'element' => '$.cnvs-block-posts-sidebar .cnvs-post-meta a:hover, $.cnvs-block-posts-sidebar .cnvs-post-meta a:focus, $.cnvs-block-posts-sidebar .post-categories a:hover, $.cnvs-block-posts-sidebar .post-categories a:focus',
'property' => 'color',
),
),
),
array(
'key' => 'colorMeta',
'label' => esc_html__( 'Post Meta', 'canvas' ),
'section' => 'color',
'type' => 'color',
'default' => '',
'output' => array(
array(
'element' => '$.cnvs-block-posts-sidebar .cnvs-post-meta span, $.cnvs-block-posts-sidebar .post-categories span',
'property' => 'color',
),
),
),
'sidebar-numbered' === $type ? array(
'key' => 'bgCounter',
'label' => esc_html__( 'Background Counter', 'canvas' ),
'section' => 'color',
'type' => 'color',
'output' => array(
array(
'element' => '$ .cnvs-post-item .cnvs-post-number',
'property' => 'background-color',
),
),
) : array(),
'sidebar-numbered' === $type ? array(
'key' => 'colorCounter',
'label' => esc_html__( 'Color Counter', 'canvas' ),
'section' => 'color',
'type' => 'color',
'output' => array(
array(
'element' => '$ .cnvs-post-item .cnvs-post-number',
'property' => 'color',
),
),
) : array(),
),
);
}
return $layouts;
}
/**
* Change post query attributes
*
* @param array $args Args for post query.
* @param array $attributes Block attributes.
* @param array $options Block options.
*/
public function change_query_args( $args, $attributes, $options ) {
// Posts count.
if ( isset( $options['widgetPostsCount'] ) && $options['widgetPostsCount'] ) {
$args['posts_per_page'] = $options['widgetPostsCount'];
}
return $args;
}
}
new CNVS_Block_Posts_Sidebar();