I am displaying random images in my homepage. My problem is, I can't get the title of the images to show in lightbox.
Here are my codes.
Codes that gets the images from the media library
function get_images_from_media_library() {
$args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'posts_per_page' => 6,
'orderby' => 'rand'
);
$query_images = new WP_Query( $args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= $image->guid;
}
return $images;
}
Code that displays the images from the media library
function display_images_from_media_library() {
$imgs = get_images_from_media_library();
$html = '<div class="no-gutter">';
foreach($imgs as $img) {
$html .= '<div class="col-lg-4 col-sm-6 photo-gallery">
<a class="portfolio-box" data-lightbox="out-of-the-box" data-title="' . $attachment->post_title . '" href="' . $img . '"><img src="' . $img . '" alt="" />
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
View <i class="fa fa-search-plus"></i>
</div>
</div>
</div>
</a></div>';
}
$html .= '</div>';
return $html; } ?>
Hope you could help me.
$attachment
is not defined anywhere!