I'm looking to add a standard 'Flickity' slider to all single.php posts on a WordPress hosted website.
I want to grab the unique attached images of a post and then display them in the slider, but I'm failing.
I'm finding it difficult to call the images from the post and display them in the slider. The post images are always different per post and the number of images also vary per post.
How could I go about this without using any WordPress plugins? I'm looking to code it in the single.php page.
Resource:
v[
^]
What I have tried:
I've tried the following code, however, this is pulling images right from the media pages (displaying only one weirdly). I might be completely wrong with this - please forgive my coding, I'm only a junior dev.
I've placed this at the top of the single.php page:
$post->ID,
'post_type' => 'attachment',
'orderby' => 'menu_order', // you can also sort images by date or be name
'order' => 'ASC',
'numberposts' => 10, // number of images (slides)
'post_mime_type' => 'image'
);
if ( $images = get_children( $args ) ) {
// if there are no images in post, don't display anything
echo '
';
foreach( $images as $image ) {
echo '
' . wp_get_attachment_image( $image->ID, 'my_slider' ) . '';
}
echo '';
}
?>