-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgallery-loop.php
More file actions
71 lines (48 loc) · 1.74 KB
/
Copy pathgallery-loop.php
File metadata and controls
71 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/* ------------------------------------------------------------------------- *
* Custom Loop Gallery
*
* 1) add the remove shortcode code in functions.php
* 2) insert the loop code in page.php or post.php
/* ------------------------------------------------------------------------- */
/* Remove default gallery shortcode from page and post (insert in functions.php) */
/*
function remove_gallery($content) {
if ( 'page' == get_post_type() || 'post' == get_post_type()) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter('the_content', 'remove_gallery');
// Remove gallery from content
add_filter('the_content', 'strip_shortcode_gallery');
function strip_shortcode_gallery( $content ) {
preg_match_all( '/'. get_shortcode_regex() .'/s', $content, $matches, PREG_SET_ORDER );
if ( ! empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
if ( 'gallery' === $shortcode[2] ) {
$pos = strpos( $content, $shortcode[0] );
if ($pos !== false)
return substr_replace( $content, '', $pos, strlen($shortcode[0]) );
}
}
}
return $content;
}
*/
/* Loop */
$gallery = get_post_gallery( $post->ID, false );
if($gallery != ''){
$ids = explode( ",", $gallery['ids'] );
/* loop image gallery */
foreach( $ids as $id ) {
$image_url = wp_get_attachment_image_src( $id , 'medium' );
$thumbnail_image = get_posts(array('p' => $id, 'post_type' => 'attachment'));
?>
<div class="gallery-item">
<img src="<?php echo $image_url[0]; ?>" />
<p><?php echo $thumbnail_image[0]->post_excerpt; ?></p>
</div>
<?php } /* end foreach */
} /* end if gallery */
?>