0

I just want to get all atachment image from post with Alt, description, title, size, resotution

and how to add DOWNLOAD button?

i want to create image downloading website on wordpress for example LINK

 <?php  $args = array(
            'post_parent'    => $post->ID,
            'post_type'      => 'attachment',
            'numberposts'    => -1, // show all
            'post_status'    => 'any',
            'post_mime_type' => 'image',
            'orderby'        => 'menu_order',
            'order'           => 'ASC'
       );

$images = get_posts($args);
if($images) { ?>
<?php foreach($images as $image) { ?>
  <img src="<?php echo wp_get_attachment_url($image->ID); ?>" >

1 Answer 1

0
<?php

/*
* Template Name: Gallery Page
*/

$query_images_args = array(
    'post_type'      => 'attachment',
    'post_mime_type' => 'image',
    'post_status'    => 'inherit',
    'posts_per_page' => - 1,
);

$query_images = new WP_Query( $query_images_args );

?>
<?php get_header();?>
<div class="main">
    <div class="row">
        <?php foreach ( $query_images->posts as $image ) {?>
            <div class="col-md-3">
                <img src="<?php echo wp_get_attachment_url($image->ID); ?>" >
<a href="<?php echo wp_get_attachment_url($image->ID); ?>" download>Download</a>
            </div>
        <?php }?>

    </div>
</div>
<?php get_footer();?>
3
  • how to get only post attachment images?
    – SauRav
    Aug 8, 2021 at 4:22
  • get attachment images only who attach to post
    – SauRav
    Aug 8, 2021 at 4:33
  • You can check with post_parent with the current loop. If you get post parent id then you can get post using post parent id
    – Nayan
    Aug 8, 2021 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.