diff --git a/amp.php b/amp.php index f73542f2911..e3df355c50d 100644 --- a/amp.php +++ b/amp.php @@ -42,8 +42,9 @@ function amp_init() { load_plugin_textdomain( 'amp', false, plugin_basename( AMP__DIR__ ) . '/languages' ); - add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK ); + add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK | EP_PAGES ); add_post_type_support( 'post', AMP_QUERY_VAR ); + add_post_type_support( 'page', AMP_QUERY_VAR ); add_action( 'wp', 'amp_maybe_add_actions' ); @@ -103,4 +104,4 @@ function amp_render() { $template = new AMP_Post_Template( $post_id ); $template->load(); exit; -} +} \ No newline at end of file diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index 5b31b813508..a57e5f0f90a 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -35,3 +35,14 @@ function is_amp_endpoint() { function amp_get_asset_url( $file ) { return plugins_url( sprintf( 'assets/%s', $file ), AMP__FILE__ ); } + +/** + * Determine if the post type is hierarchical as template handling is slightly different + * + * @var $post_id int + * + * @return boolean + */ +function is_amp_content_hierarchical( $post_id ) { + return (boolean) is_post_type_hierarchical( get_post_type( $post_id ) ); +} \ No newline at end of file diff --git a/includes/class-amp-post-template.php b/includes/class-amp-post-template.php index bf9c200b402..18a8072a298 100644 --- a/includes/class-amp-post-template.php +++ b/includes/class-amp-post-template.php @@ -62,7 +62,12 @@ public function get( $property, $default = null ) { } public function load() { - $this->load_parts( array( 'single' ) ); + + if( is_amp_content_hierarchical( $this->ID ) ) { + $this->load_parts( array( 'page' ) ); + } else { + $this->load_parts( array( 'single' ) ); + } } public function load_parts( $templates ) { @@ -109,21 +114,30 @@ private function build_post_data() { $metadata = array( '@context' => 'http://schema.org', - '@type' => 'BlogPosting', 'mainEntityOfPage' => $this->get( 'canonical_url' ), 'publisher' => array( '@type' => 'Organization', 'name' => $this->get( 'blog_name' ), ), 'headline' => $post_title, - 'datePublished' => date( 'c', $post_publish_timestamp ), - 'dateModified' => date( 'c', $post_modified_timestamp ), - 'author' => array( - '@type' => 'Person', - 'name' => $post_author->display_name, - ), ); + if( is_amp_content_hierarchical( $this->ID ) ) { + $article_meta = array( + '@type' => 'WebPage' + ); + } else { + $article_meta = array( + '@type' => 'BlogPosting', + 'datePublished' => date( 'c', $post_publish_timestamp ), + 'dateModified' => date( 'c', $post_modified_timestamp ), + 'author' => array( + '@type' => 'Person', + 'name' => $post_author->display_name, + ), + ); + } + $site_icon_url = $this->get( 'site_icon_url' ); if ( $site_icon_url ) { $metadata['publisher']['logo'] = array( diff --git a/templates/page.php b/templates/page.php new file mode 100644 index 00000000000..e5cfe9d0932 --- /dev/null +++ b/templates/page.php @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + +