wordpress - Display all post image gallery using the shortcode [gallery] -
i want display images post gallery "gallery". :<?php echo do_shortcode('[gallery]'); ?>
after search, learned needed use "preg_match" function ids of images gallery. :
$post_content = $post->post_content; preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); $array_id = explode(",", $ids[1]);
but don't know how use ... i'm newbie , it's quite difficult me use that. should put code in functions file ? if yes how can please ?
the aim it's put final code : <?php echo do_shortcode( '[gallery ids="$array_id"]' ); ?>
thank , sorry english !!!
i found solution, share you. maybe interested that.
i modified following code :
$post_content = $post->post_content; preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); $array_id = explode(",", $ids[1]);
into :
<?php global $post; $post_content = $post->post_content; preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); $images_id = explode(",", $ids[1]); echo do_shortcode('[gallery type="slideshow" ids="'. implode(',', array_slice($images_id, 0, 3)).' ,"]'); ?>
and inserted in custom format-gallery.php
, works fine. notice have limited automatically number of ids returned array_slice()
.
i hope someone.
Comments
Post a Comment