*/ public static function build( Node_Context $c, bool $breadcrumb, bool $has_image ): array { $type = self::type( $c->context ); $node = array( '@type' => $type, '@id' => $c->id( 'webpage' ), 'url' => $c->url, 'name' => $c->title(), 'isPartOf' => array( '@id' => Ids::website() ), 'inLanguage' => get_bloginfo( 'language' ), ); $description = $c->description(); if ( '' !== $description ) { $node['description'] = $description; } $post = $c->post(); if ( null !== $post && in_array( $c->context->type(), array( Context::SINGULAR, Context::ATTACHMENT ), true ) ) { $node['datePublished'] = get_post_time( 'c', false, $post ); $node['dateModified'] = get_post_modified_time( 'c', false, $post ); } if ( $breadcrumb ) { $node['breadcrumb'] = array( '@id' => $c->id( 'breadcrumb' ) ); } if ( $has_image ) { $node['primaryImageOfPage'] = array( '@id' => $c->id( 'primaryimage' ) ); $node['image'] = array( '@id' => $c->id( 'primaryimage' ) ); } if ( 'ProfilePage' === $type && null !== $c->context->user() ) { $node['mainEntity'] = array( '@id' => Ids::author( $c->context->user()->ID ) ); } return $node; } /** * The type of page node for a context. * * @since 1.0.0 * * @param Context $context Page context. * @return string */ public static function type( Context $context ): string { switch ( $context->type() ) { case Context::SEARCH: return 'SearchResultsPage'; case Context::AUTHOR: return 'ProfilePage'; case Context::TERM: case Context::DATE: case Context::POST_TYPE_ARCHIVE: case Context::HOME: return 'CollectionPage'; } return 'WebPage'; } }