0

I am trying to show all images on a page in WordPress. My WordPress page is setup like you see in the image below.

enter image description here

What I want to do is show each of these images on a custom page I have made, called Portrait Album. See code below. I guess it is the opposite of this that I want to implement.

I am not sure how I can show each image in the Text section. Does anyone out there know how to do this? Should be obvious but I cannot find an answer anywhere.

I know get_content() will show the content, but how can I specifically show the images, so I can show these in a loop enabling me to make a grid using CSS and create a photo gallery.

Currently this is the code I have:

<?php /* Template Name: Portrait Album */ ?>
<?php get_header(); ?>
<div class="portrait-page" style="background-color: black;">
     <?php if (have_posts()) : while (have_posts()) : the_post();?>
     <?php the_content(); ?>
     echo "<img src='".wp_get_attachment_url( $the_post->ID )."' />";
    <?php endwhile; endif; ?>
    </div>
  </div>
</div>

What I want to do is something like this, where col-1-3 is one-third of the width of the page

<div class="row">
  <div class="col-1-3">
    echo "<img src='"RELEVANT PHP CODE HERE"' />"
  </div>
</div>
0

I'm not sure I 100% grasp what you're trying to do, but I believe using WordPress' default Gallery shortcode is what you want. When you insert an image into the content using the "Add Media" button, you can create a gallery and say how many columns you want the gallery to be.

If mark-up doesn't line-up well you could always repurpose the shortcode with your own mark-up, by using remove_shortcode( 'gallery' ); and then coding up your own function and doing an add_shortcode( 'gallery', 'my_gallery_shortcode );

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.