WPSEO_Post_Type_Sitemap_Provider::get_index_links
Retrieves the sitemap links.
Метод класса: WPSEO_Post_Type_Sitemap_Provider{}
Хуков нет.
Возвращает
array.
Использование
$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 28.4
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 ) {
$all_dates = version_compare( $wpdb->db_version(), '8.0', '>=' ) ? $this->get_all_dates_using_with_clause( $post_type, $max_entries ) : $this->get_all_dates( $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;
}