| 1 |
<?php |
| 2 |
|
| 3 |
// Hook the post rendering to the block |
| 4 |
if ( function_exists( 'register_block_type' ) ) : |
| 5 |
register_block_type( |
| 6 |
'ew-block/ew-archive', |
| 7 |
array( |
| 8 |
'attributes' => array( |
| 9 |
'title' => array( |
| 10 |
'type' => 'string', |
| 11 |
'default' => 'Archives', |
| 12 |
), |
| 13 |
'limit' => array( |
| 14 |
'type' => 'number', |
| 15 |
'default' => 10, |
| 16 |
), |
| 17 |
'type' => array( |
| 18 |
'type' => 'string', |
| 19 |
'default' => 'monthly', |
| 20 |
), |
| 21 |
'post_type' => array( |
| 22 |
'type' => 'string', |
| 23 |
'default' => 'post', |
| 24 |
), |
| 25 |
'order' => array( |
| 26 |
'type' => 'string', |
| 27 |
'default' => 'asc', |
| 28 |
), |
| 29 |
'format' => array( |
| 30 |
'type' => 'string', |
| 31 |
'default' => 'html', |
| 32 |
), |
| 33 |
'before' => array( |
| 34 |
'type' => 'string', |
| 35 |
'default' => '', |
| 36 |
), |
| 37 |
'after' => array( |
| 38 |
'type' => 'string', |
| 39 |
'default' => '', |
| 40 |
), |
| 41 |
'show_post_count' => array( |
| 42 |
'type' => 'boolean', |
| 43 |
'default' => false, |
| 44 |
), |
| 45 |
'is_block' => array( |
| 46 |
'type' => 'boolean', |
| 47 |
'default' => true, |
| 48 |
), |
| 49 |
), |
| 50 |
'render_callback' => 'ew_archive_render_shortcode', |
| 51 |
) |
| 52 |
); |
| 53 |
endif; |
| 54 |
|
| 55 |
if ( ! function_exists( 'ew_archive_render_shortcode' ) ) : |
| 56 |
add_shortcode( 'ew-archive', 'ew_archive_render_shortcode' ); |
| 57 |
function ew_archive_render_shortcode( $atts ) { |
| 58 |
$instance['title'] = $atts['title']; |
| 59 |
$instance['limit'] = $atts['limit']; |
| 60 |
$instance['type'] = $atts['type']; |
| 61 |
$instance['post_type'] = $atts['post_type']; |
| 62 |
$instance['order'] = $atts['order']; |
| 63 |
$instance['format'] = $atts['format']; |
| 64 |
$instance['before'] = $atts['before']; |
| 65 |
$instance['after'] = $atts['after']; |
| 66 |
$instance['show_post_count'] = $atts['show_post_count']; |
| 67 |
$instance['is_block'] = $atts['is_block']; |
| 68 |
|
| 69 |
$ew_archive = new EW_Archives(); |
| 70 |
|
| 71 |
return $ew_archive->shortcode( $instance ); |
| 72 |
} |
| 73 |
endif; |
| 74 |
|