WPSEO_Post_Type_Sitemap_Provider::get_sitemap_links() public Yoast 1.0
Get set of sitemap link data.
{} Это метод класса: WPSEO_Post_Type_Sitemap_Provider{}
Хуки из метода
Возвращает
Массив.
Использование
$WPSEO_Post_Type_Sitemap_Provider = new WPSEO_Post_Type_Sitemap_Provider(); $WPSEO_Post_Type_Sitemap_Provider->get_sitemap_links( $type, $max_entries, $current_page );
- $type(строка) (обязательный)
- Sitemap type.
- $max_entries(число) (обязательный)
- Entries per sitemap.
- $current_page(число) (обязательный)
- Current page of the sitemap.
Код WPSEO_Post_Type_Sitemap_Provider::get_sitemap_links() WPSEO Post Type Sitemap Provider::get sitemap links Yoast 15.9
public function get_sitemap_links( $type, $max_entries, $current_page ) {
$links = [];
$post_type = $type;
if ( ! $this->is_valid_post_type( $post_type ) ) {
throw new OutOfBoundsException( 'Invalid sitemap page requested' );
}
$steps = min( 100, $max_entries );
$offset = ( $current_page > 1 ) ? ( ( $current_page - 1 ) * $max_entries ) : 0;
$total = ( $offset + $max_entries );
$post_type_entries = $this->get_post_type_count( $post_type );
if ( $total > $post_type_entries ) {
$total = $post_type_entries;
}
if ( $current_page === 1 ) {
$links = array_merge( $links, $this->get_first_links( $post_type ) );
}
// If total post type count is lower than the offset, an invalid page is requested.
if ( $post_type_entries < $offset ) {
throw new OutOfBoundsException( 'Invalid sitemap page requested' );
}
if ( $post_type_entries === 0 ) {
return $links;
}
$posts_to_exclude = $this->get_excluded_posts( $type );
while ( $total > $offset ) {
$posts = $this->get_posts( $post_type, $steps, $offset );
$offset += $steps;
if ( empty( $posts ) ) {
continue;
}
foreach ( $posts as $post ) {
if ( in_array( $post->ID, $posts_to_exclude, true ) ) {
continue;
}
if ( WPSEO_Meta::get_value( 'meta-robots-noindex', $post->ID ) === '1' ) {
continue;
}
$url = $this->get_url( $post );
if ( ! isset( $url['loc'] ) ) {
continue;
}
/**
* Filter URL entry before it gets added to the sitemap.
*
* @param array $url Array of URL parts.
* @param string $type URL type.
* @param object $post Data object for the URL.
*/
$url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $post );
if ( ! empty( $url ) ) {
$links[] = $url;
}
}
unset( $post, $url );
}
return $links;
}