Horje
Getting images attached to a post - Wordpress Solution
[Solved] - Getting images attached to a post - Wordpress Solution
Try following codes
I use the code below, which works great,
function my_attachment_gallery($postid=0, $size='thumbnail', $attributes='') {
	if ($postid<1) $postid = get_the_ID();
	if ($images = get_children(array(
		'post_parent' => $postid,
		'post_type' => 'attachment',
		'order' => 'DESC',
		'numberposts' => 0,
		'post_mime_type' => 'image',)))
		foreach($images as $image) {
			$attachment=wp_get_attachment_image_src($image->ID, $size);
			?><div class="feature"><img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> /></div><?php
		}
}
I then add this to my post template
<?php my_attachment_gallery(0, 'medium', 'alt="' . $post->post_title . '"'); ?>
With that I can choose whether to show thumb, medium, large or full. What I need to be included here is that when the image is clicked I get the attachment image (large or full). I know gallery does this, but I need more control here in showing all images attached to the post. My goal is to design a "slideshow" within
<div class="feature"><img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> /></div>
the featured div

Solution - 1

Something like this?

function my_attachment_gallery($postid=0, $size='thumbnail', $attributes='') {

	if ($postid<1) $postid = get_the_ID();

	if ($images = get_children(array(

		'post_parent' => $postid,

		'post_type' => 'attachment',

		'order' => 'DESC',

		'numberposts' => 0,

		'post_mime_type' => 'image',)))

		foreach($images as $image) {

			$attachment=wp_get_attachment_image_src($image->ID, $size);
			$full_attachment=wp_get_attachment_image_src($image->ID, 'full');

			?><div class="feature"><a href="<?php echo $full_attachment[0]; ?>"><img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> /></a></div><?php

		}

}

Date: 2022-10-21 05:22:44
Category: Wordpress
More for You