array( 'categories' => array( 'type' => 'string', ), 'className' => array( 'type' => 'string', ), 'postsToShow' => array( 'type' => 'number', 'default' => 5, ), 'displayPostDate' => array( 'type' => 'boolean', 'default' => true, ), 'displayPostExcerpt' => array( 'type' => 'boolean', 'default' => true, ), 'displayReadMore' => array( 'type' => 'boolean', 'default' => false, ), 'displayFeaturedImage' => array( 'type' => 'boolean', 'default' => true, ), 'displayPostAuthor' => array( 'type' => 'boolean', 'default' => true, ), 'readMoreText' => array( 'type' => 'string', 'default' => false, ), 'postLayout' => array( 'type' => 'string', 'default' => 'list', ), 'columns' => array( 'type' => 'number', 'default' => 2, ), 'align' => array( 'type' => 'string', 'default' => 'center', ), 'order' => array( 'type' => 'string', 'default' => 'desc', ), 'orderBy' => array( 'type' => 'string', 'default' => 'date', ), ), 'render_callback' => 'render_block_advanced_posts_grid', ) ); } add_action( 'init', 'register_block_advanced_posts_grid' ); /** * Renders the `advanced/posts-grid` block on server. * * @param array $attributes The block attributes. * * @return string Returns the post content with latest posts added. */ function render_block_advanced_posts_grid( $attributes ) { $recent_posts = wp_get_recent_posts( array( 'numberposts' => $attributes['postsToShow'], 'post_status' => 'publish', 'order' => $attributes['order'], 'orderby' => $attributes['orderBy'], 'category' => isset( $attributes['categories'] ) ? $attributes['categories'] : false, ), 'OBJECT' ); $list_items_markup = ''; foreach ( $recent_posts as $post ) { $post_id = $post->ID; $title = get_the_title( $post_id ); $author_id = $post->post_author; $list_items_markup .= '