From ce45015e39ed8f461e856dec797b290dd102b97a Mon Sep 17 00:00:00 2001 From: Rastislav Lamos Date: Wed, 24 May 2017 12:30:32 +0200 Subject: [PATCH] Add server-side rendering I also had to rename the block from core/latest-posts to core/latestposts since I think there's a bug in the server-side matcher -- it ignores block comments with hyphens: #882 --- blocks/library/latest-posts/index.js | 2 +- blocks/library/latest-posts/index.php | 37 +++++++++++++++++++++++++++ index.php | 8 ++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 blocks/library/latest-posts/index.php diff --git a/blocks/library/latest-posts/index.js b/blocks/library/latest-posts/index.js index 698db803494c4..e0166319a96a5 100644 --- a/blocks/library/latest-posts/index.js +++ b/blocks/library/latest-posts/index.js @@ -10,7 +10,7 @@ import { registerBlock } from '../../api'; import { getLatestPosts } from './data.js'; -registerBlock( 'core/latest-posts', { +registerBlock( 'core/latestposts', { title: wp.i18n.__( 'Latest Posts' ), icon: 'list-view', diff --git a/blocks/library/latest-posts/index.php b/blocks/library/latest-posts/index.php new file mode 100644 index 0000000000000..3956da2b53d82 --- /dev/null +++ b/blocks/library/latest-posts/index.php @@ -0,0 +1,37 @@ + $postsToShow, + 'post_status' => 'publish' + ) ); + + $posts_content = ''; + + foreach( $recent_posts as $post ) { + $post_permalink = get_permalink( $post['ID'] ); + + $posts_content .= "
  • {$post['post_title']}
  • \n"; + } + + $block_content = << + + + +CONTENT; + + return $block_content; +} + +register_block( 'core/latestposts', array( + 'render' => 'gutenberg_block_core_latest_posts' +) ); diff --git a/index.php b/index.php index 096892b51a7e2..a6b45aa6c112c 100644 --- a/index.php +++ b/index.php @@ -8,6 +8,9 @@ * @package gutenberg */ +define( 'GUTENBERG__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); +define( 'GUTENBERG__BLOCKS_LIBRARY_DIR', GUTENBERG__PLUGIN_DIR . 'blocks/library' ); + /** * Gutenberg's Menu. * @@ -565,3 +568,8 @@ function the_gutenberg_project() {