Okay, this is code which i dress in category, and tag pages. It shows all of the accessories from the 8 newest posts, inside a given category or tag. Therefore if I am around the 'cars' category page, it shows only photos from posts which were categorized as 'cars'. That part is effective.

What I am attempting to do is have it to ensure that even when you will find several posts for the reason that category, if none of individuals posts have accessories, it'll echo something similar to, "sorry no photos here".

<?php if (have_posts()) : ?>

               <?php while (have_posts()) : the_post(); ?>    

 <?php
$args = array( 'post_type' => 'attachment', 'numberposts' => 8, 'post_status' => null, 'post_parent' => $post->ID ); 
$attachments = get_posts($args);
if ($attachments) {
    foreach ( $attachments as $attachment ) {
        echo '<li>';
        the_attachment_link( $attachment->ID , false );
        echo '</li>';
    }
}

?> <?php endwhile; ?>
     <?php endif; ?>

I have attempted adding an else statement, such as this:

<?php endwhile; else: ?>
 <p>sorry no photos here</p>
 <?php endif; ?>

However, if a person publish includes a photo however the other does not it shows that certain photo it echos the else statement.

Phew! Lengthy explanation. This is not existence or dying but I have spent a lot time onto it with no success, I am most likely a lot more hassled because of it than I ought to be. :/

Thanks ahead of time!

Wordpress source: http://codex.wordpress.org/Template_Tags/get_posts#Show_all_attachments

Your else is incorporated in the wrong place, it's serving as an else condition on have_posts() you really need it to become an else condition on if ($accessories) like so:

if ($attachments) {
    foreach ( $attachments as $attachment ) {
        echo '<li>';
        the_attachment_link( $attachment->ID , false );
        echo '</li>';
    }
}
else
{
    echo "sorry no photos here";
}

and when that does not work try:

if (count($attachments)>0) {
    foreach ( $attachments as $attachment ) {
        echo '<li>';
        the_attachment_link( $attachment->ID , false );
        echo '</li>';
    }
}
else
{
    echo "sorry no photos here";
}

Sorry, the energy went inside my work...

And So I did this:

if ($attachments) {
    var_dump($attachments);
    foreach ( $attachments as $attachment ) {
        echo '<li>';
        the_attachment_link( $attachment->ID , false );
        echo '</li>';
    }
}
else
{
    echo "sorry no photos here";
}

And also got this:

NULL array(1) publish_author"]=> string(1) "1" ["publish_date"]=> string(19) "2011-03-24 03:50:31" ["publish_date_gmt"]=> string(19) "2011-03-24 10:50:31" ["publish_content"]=> string() "" ["publish_title"]=> string(7) "Joe Ahn" ["show_in_menu"]=> string(1) "1" ["link_link"]=> string(1) "1" ["no_follow_link"]=> string(1) "" ["alt_link_text"]=> NULL ["custom_link_class"]=> NULL ["redirect_url"]=> NULL ["target_blank"]=> string(1) "" ["alt_title_attribute"]=> NULL ["publish_excerpt"]=> string() "" ["publish_status"]=> string(7) "inherit" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["publish_password"]=> string() "" ["publish_title"]=> string(3) "ahn" ["to_ping"]=> string() "" ["pinged"]=> string() "" ["publish_modified"]=> string(19) "2011-03-24 03:50:31" ["publish_modified_gmt"]=> string(19) "2011-03-24 10:50:31" ["publish_content_strained"]=> string() "" ["publish_parent"]=> int(64) ["guid"]=> string(66) "http://www.ouhsd.k12.ca.us/news/wordpress-content/uploads/2011/03/ahn.digital" ["menu_order"]=> int() ["publish_type"]=> string(10) "attachment" ["publish_mime_type"]=> string(10) "image/jpeg" ["comment_count"]=> string(1) "" ["filter"]=> string(3) "raw"