WPSEO_Post_Type_Sitemap_Provider::get_index_links()
Retrieves the sitemap links.
Метод класса: WPSEO_Post_Type_Sitemap_Provider{}
Хуков нет.
Возвращает
Массив
.
Использование
$WPSEO_Post_Type_Sitemap_Provider = new WPSEO_Post_Type_Sitemap_Provider(); $WPSEO_Post_Type_Sitemap_Provider->get_index_links( $max_entries );
- $max_entries(int) (обязательный)
- Entries per sitemap.
Код WPSEO_Post_Type_Sitemap_Provider::get_index_links() WPSEO Post Type Sitemap Provider::get index links Yoast 20.0
public function get_index_links( $max_entries ) { global $wpdb; $post_types = WPSEO_Post_Type::get_accessible_post_types(); $post_types = array_filter( $post_types, [ $this, 'is_valid_post_type' ] ); $last_modified_times = WPSEO_Sitemaps::get_last_modified_gmt( $post_types, true ); $index = []; foreach ( $post_types as $post_type ) { $total_count = $this->get_post_type_count( $post_type ); if ( $total_count === 0 ) { continue; } $max_pages = 1; if ( $total_count > $max_entries ) { $max_pages = (int) ceil( $total_count / $max_entries ); } $all_dates = []; if ( $max_pages > 1 ) { $post_statuses = array_map( 'esc_sql', WPSEO_Sitemaps::get_post_statuses( $post_type ) ); $sql = " SELECT post_modified_gmt FROM ( SELECT @rownum:=0 ) init JOIN {$wpdb->posts} USE INDEX( type_status_date ) WHERE post_status IN ('" . implode( "','", $post_statuses ) . "') AND post_type = %s AND ( @rownum:=@rownum+1 ) %% %d = 0 ORDER BY post_modified_gmt ASC "; $all_dates = $wpdb->get_col( $wpdb->prepare( $sql, $post_type, $max_entries ) ); } for ( $page_counter = 0; $page_counter < $max_pages; $page_counter++ ) { $current_page = ( $page_counter === 0 ) ? '' : ( $page_counter + 1 ); $date = false; if ( empty( $current_page ) || $current_page === $max_pages ) { if ( ! empty( $last_modified_times[ $post_type ] ) ) { $date = $last_modified_times[ $post_type ]; } } else { $date = $all_dates[ $page_counter ]; } $index[] = [ 'loc' => WPSEO_Sitemaps_Router::get_base_url( $post_type . '-sitemap' . $current_page . '.xml' ), 'lastmod' => $date, ]; } } return $index; }