如何从帖子中获取所有附件图片??WordPress

时间:2021-08-08 作者:SauRav

我只想用Alt, description, title, size, resotution

如何添加下载按钮?

例如,我想在wordpress上创建图像下载网站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 个回复
SO网友:Nayan
<?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();?>