get_post_gallery

函数
get_post_gallery ( $post = 0, $html = true )
参数
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global $post.
    Required:
  • (bool) $html Optional. Whether to return HTML or data. Default is true.
    Required:
    Default: true
返回值
  • (string|array) Gallery data and srcs parsed from the expanded shortcode.
定义位置
相关方法
get_post_galleriesget_post_gallery_imagesget_post_galleries_imagesget_post_statesget_post_parent
引入
3.6.0
弃用
-

get_post_gallery函数返回文章中特定图库的HTML。它有两个参数:第一个参数是文章的ID,第二个参数是画廊的ID。

检查指定文章的内容是否有画廊,如果有,返回第一个。

function get_post_gallery( $post = 0, $html = true ) {
	$galleries = get_post_galleries( $post, $html );
	$gallery   = reset( $galleries );

	/**
	 * Filters the first-found post gallery.
	 *
	 * @since 3.6.0
	 *
	 * @param array       $gallery   The first-found post gallery.
	 * @param int|WP_Post $post      Post ID or object.
	 * @param array       $galleries Associative array of all found post galleries.
	 */
	return apply_filters( 'get_post_gallery', $gallery, $post, $galleries );
}

常见问题

FAQs
查看更多 >