Answer the question
In order to leave comments, you need to log in
How to display photo description in WordPress?
The gallery on the site is formed as follows
<?php
if( has_shortcode( $post->post_content, 'gallery' ) ) {
$gallery = get_post_gallery_images( $post->ID );
foreach( $gallery as $image ) {
?>
<div class="gallery-box-img">
<div class="gallery-img">
<a href="<?php echo str_replace('-150x150','',$image); ?>" class="lightbox" rel="gallery">
<img src="<?php echo $image; ?>" alt="">
</a>
</div>
</div>
<?php
}
}
?>
Answer the question
In order to leave comments, you need to log in
1. Why use `has_shortcode();`, it's possible in another way...
2. Slightly modified suggestion by @ZetRider :
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
// array of ids;
$ids = explode(',', $gallery['ids']);
// array of urls;
$images = $gallery['src'];
$i = 0;
foreach( $images as $image ) {
$title = get_the_title($ids[$i]);
// тут свой формат вывода
echo '<img src="'.$image.'"><span>'.$title.'</span><br>';
$i++;
}
endif;
It is possible like this:
if( has_shortcode( $post->post_content, 'gallery' ) ) {
$gallery = get_post_gallery($post->ID, false);
$gallery_ids = explode(',', $gallery['ids']);
$g_i = 0;
foreach( $gallery['src'] as $image ) {
$title_img = get_the_title($gallery_ids[$g_i]);
?>
<div class="gallery-box-img">
<div class="gallery-img">
<a href="<?php echo str_replace('-150x150','',$image); ?>" class="lightbox" rel="gallery">
<img src="<?php echo $image; ?>" alt="<?php echo $title_img; ?>">
</a>
</div>
</div>
<?php
$g_i++;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question