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

wordpress函数get_post_gallery()用法示例

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

Check a specified post’s content for gallery and, if present, return the first


描述


参数

$post

(int|WP_Post)
(Optional)
Post ID or WP_Post object. Default is global $post.

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

$html

(bool)
(Optional)
Whether to return HTML or data. Default is true.

Default value: true


返回值

(string|array) Gallery data and srcs parsed from the expanded shortcode.


源代码

File: wp-includes/media.php

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 );
}

更新日志

Version 描述
3.6.0 Introduced.

相关函数

Uses

  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/media.php:
    get_post_galleries()
  • wp-includes/media.php:
    get_post_gallery

Used By

  • wp-includes/media.php:
    get_post_gallery_images()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Julien Liabeuf

    If there is no gallery present in the page, the function will return false (boolean).

  2. Example
    Output each image in a gallery with our own custom image class when using data output and not HTML:

    
    <?php
    /* The loop */
    while ( have_posts() ) : the_post();
    	if ( $gallery = get_post_gallery( get_the_ID(), false ) ) :
    		// Loop through all the image and output them one by one.
    		foreach ( $gallery['src'] AS $src ) {
    	                ?>                
    	                <img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
    			<?php
    		}
    	endif;
    endwhile;
    ?>
    

    Example data output

    
    array (size=3)
      'link' => string 'file' (length=4)
      'ids' => string '423,424,425,426' (length=15)
      'src' => 
        array (size=4)
          0 => string 'http://www.yoursite.com/wp-content/uploads/2013/10/1296136694836-150x150.jpg' (length=85)
          1 => string 'http://www.yoursite.com/wp-content/uploads/2013/10/1315981706292-150x150.jpg' (length=85)
          2 => string 'http://www.yoursite.com/wp-content/uploads/2013/10/fate-stay-night-446-wall1200-150x150.jpg' (length=100)
          3 => string 'http://www.yoursite.com/wp-content/uploads/2013/10/GpTq3-150x150.jpg' (length=77)
    

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

热门推荐

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

反馈