• Posted: 2011-08-04
  • Author: Chris Robinson
  • Tags:

Check if post has more than one image attached

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
<?php
$attachments = get_children(
    array(
	'post_type' => 'attachment',
	'post_mime_type' => 'image',
	'post_parent' => $post->ID
    ));
if(count($attachments) > 1) { ?>
    <!-- Do something like show a slider -->
<?php } else { ?>
    <!-- Display a single image -->
<?php } ?>

Instructions:

A pretty simple if statement, wrote this up for my theme framework. In my case I used it to check if the post has more than one image display a slider, else display the single image.


Share this snippet

If you like this snippet, share it with friends!