Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am tryin to insert all pictures in media to page. By meaning all pictures, everything added in blog. I ve been looking this feature all day. Is there any shortcode for that or something easy to make it?

Thanks in advance.

share|improve this question

1 Answer 1

First, you need to create a custom page Template, to hold your custom loop output. Create a Theme file, named e.g. template-all-images.php, with the following header:

<?php
/**
 * Template name: All Images
 */
?>

Then, in the custom page template, you need to query for all image attachments. Try using WP_Query(), with post type/status arguments:

<?php
$images_query_args = array(
    'post_type' => 'attachment',
    'post_status' => 'inherit',
    'post_mime_type' => 'image'
);

$images_query = new WP_Query( $images_query_args );
?>

Then, output the query:

<?php
if ( $images_query->have_posts() ) : while ( $images_query->have_posts() ) : $images_query->the_post();

    // Normal loop output goes here

endwhile; endif;

// Be kind; rewind
wp_reset_postdata();
?>

For your loop output, if you just want to output a fully formed image, you can use e.g. wp_get_attachment_image():

<?php
wp_get_attachment_image( get_the_ID(), 'large' );
?>

(Replace 'large' with your desired image size, or omit, to use the default size, 'thumbnail'.)

The entire custom page template file might look like the following:

<?php
/**
 * Template name: All Images
 */

// Get the header
get_header();

// Image attachment query arguments
$images_query_args = array(
    'post_type' => 'attachment',
    'post_status' => 'inherit',
    'post_mime_type' => 'image'
);
// Query image attachments
$images_query = new WP_Query( $images_query_args );

// Image attachment query loop
if ( $images_query->have_posts() ) : while ( $images_query->have_posts() ) : $images_query->the_post();

    // Output the attachment image
    wp_get_attachment_image( get_the_ID(), 'large' );

endwhile; endif;

// Be kind; rewind
wp_reset_postdata();

// Get the footer
get_footer();
?>

Using your custom page template

  1. Be sure that template-all-images.php is saved to your Theme directory under wp-content/themes/{theme-name}.
  2. Create a new static page
  3. Under the Page Attributes meta box, assign the "All Images" template to the page
  4. Publish the page

Edits

Edits incorporated into the question.

share|improve this answer
    
Sorry to bother, I am not good at codeing. could you be more specific please. Thank you very much. –  tolga May 29 '12 at 13:49
    
About what do you need me to be more specific? –  Chip Bennett May 29 '12 at 13:58
    
in which file i hve to put these code in? and how to use in site? –  tolga May 29 '12 at 14:11
    
See updated answer. –  Chip Bennett May 29 '12 at 14:21
    
Chip, thank you very. –  tolga May 29 '12 at 14:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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