name = 'entities'; $this->object_type = 'entity'; } public function get_url_list( $page_num, $object_subtype = '' ) { // Only list entities that appear in currently published, public // content — matching what the entity pages will actually serve. $public_ids = Semantic_Entity_Registry::public_registry_ids(); if ( empty( $public_ids ) ) return []; global $wpdb; $per = 2000; $offset = ( $page_num - 1 ) * $per; $in = implode( ',', array_map( 'intval', $public_ids ) ); $rows = $wpdb->get_col( $wpdb->prepare( "SELECT entity_id FROM {$wpdb->prefix}semantic_entity_registry WHERE id IN ($in) ORDER BY occurrence_count DESC LIMIT %d OFFSET %d", $per, $offset ) ); $urls = []; foreach ( $rows as $eid ) $urls[] = [ 'loc' => home_url( '/entities/' . $eid ) ]; return $urls; } public function get_max_num_pages( $object_subtype = '' ) { $count = count( Semantic_Entity_Registry::public_registry_ids() ); return max( 1, (int) ceil( $count / 2000 ) ); } }; wp_register_sitemap_provider( 'semantic-entities', $provider ); } public static function add_rewrite() { add_rewrite_rule( '^entities/([^/]+)/?$', 'index.php?' . self::QUERY_VAR . '=$matches[1]', 'top' ); } public static function query_vars( $vars ) { $vars[] = self::QUERY_VAR; return $vars; } public static function maybe_render() { $entity_id = get_query_var( self::QUERY_VAR ); if ( ! $entity_id ) return; $entity = Semantic_Entity_Registry::get_by_entity_id( $entity_id ); // Only serve entities that occur in currently published, public content — // a canonical page for an entity known only from drafts would leak it. if ( ! $entity || ! Semantic_Entity_Registry::is_public( $entity ) ) { status_header( 404 ); return; // let WP show its 404 template } foreach ( [ 'same_as', 'synonyms' ] as $col ) { $entity[ $col ] = json_decode( $entity[ $col ] ?? '[]', true ) ?: []; } status_header( 200 ); self::render( $entity ); exit; } private static function render( $entity ) { // Stored raw; each value is escaped once, at its output point below. $name = $entity['label']; $def = $entity['definition'] ?? ''; $type = $entity['type'] ?? ''; $org = Semantic_Settings::org_name(); // Register + enqueue this page's stylesheet via the WP API, then print only // this handle in . The page renders outside the template hierarchy // (no wp_head fires), so we print the single registered handle directly // rather than pulling the whole document head in via wp_head(). wp_register_style( 'semantic-entity-page', SEMANTIC_URL . 'public/entity-page.css', [], SEMANTIC_VERSION ); wp_enqueue_style( 'semantic-entity-page' ); // JSON-LD for the entity $jsonld = [ '@context' => 'https://schema.org', '@type' => 'Thing', '@id' => home_url( '/entities/' . $entity['entity_id'] ), 'name' => $entity['label'], 'description' => $entity['definition'] ?? '', ]; if ( ! empty( $entity['same_as'] ) ) $jsonld['sameAs'] = $entity['same_as']; if ( ! empty( $entity['synonyms'] ) ) $jsonld['alternateName'] = $entity['synonyms']; header( 'Content-Type: text/html; charset=utf-8' ); ?> > <?php echo esc_html( $name ); ?> — <?php echo esc_html( $org ); ?>
· Entity

Also known as