^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_post_galleries()用法示例

get_post_galleries( int|WP_Post $post,  bool $html = true )

Retrieves galleries from the passed post’s content.


描述


参数

$post

(int|WP_Post)
(Required)
Post ID or object.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$html

(bool)
(Optional)
Whether to return HTML or data in the array.

Default value: true


返回值

(array) A list of arrays, each containing gallery data and srcs parsed from the expanded shortcode.


源代码

File: wp-includes/media.php

function get_post_galleries( $post, $html = true ) {
	if ( ! $post = get_post( $post ) )
		return array();

	if ( ! has_shortcode( $post->post_content, 'gallery' ) )
		return array();

	$galleries = array();
	if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) {
		foreach ( $matches as $shortcode ) {
			if ( 'gallery' === $shortcode[2] ) {
				$srcs = array();

				$shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
				if ( ! is_array( $shortcode_attrs ) ) {
					$shortcode_attrs = array();
				}

				// Specify the post id of the gallery we're viewing if the shortcode doesn't reference another post already.
				if ( ! isset( $shortcode_attrs['id'] ) ) {
					$shortcode[3] .= ' id="' . intval( $post->ID ) . '"';
				}

				$gallery = do_shortcode_tag( $shortcode );
				if ( $html ) {
					$galleries[] = $gallery;
				} else {
					preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
					if ( ! empty( $src ) ) {
foreach ( $src as $s ) {
$srcs[] = $s[2];
}
					}

					$galleries[] = array_merge(
$shortcode_attrs,
array(
'src' => array_values( array_unique( $srcs ) )
)
					);
				}
			}
		}
	}

	/**
	 * Filters the list of all found galleries in the given post.
	 *
	 * @since 3.6.0
	 *
	 * @param array   $galleries Associative array of all found post galleries.
	 * @param WP_Post $post      Post object.
	 */
	return apply_filters( 'get_post_galleries', $galleries, $post );
}

更新日志

Version 描述
3.6.0 Introduced.

相关函数

Uses

  • wp-includes/shortcodes.php:
    has_shortcode()
  • wp-includes/shortcodes.php:
    get_shortcode_regex()
  • wp-includes/shortcodes.php:
    shortcode_parse_atts()
  • wp-includes/shortcodes.php:
    do_shortcode_tag()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/media.php:
    get_post_galleries
  • wp-includes/post.php:
    get_post()
  • Show 2 more uses


Used By

  • wp-includes/media.php:
    get_post_gallery()
  • wp-includes/media.php:
    get_post_galleries_images()

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈