Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 '';
}
?>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900