views:

10

answers:

2

Hi,

I'm currently developing a custom theme for a client of mine. What I want to do is retrieve all the attachments (= images) in the installation via wp_getposts (http://codex.wordpress.org/Function_Reference/get_posts).

That code would be:

$attachments = get_posts('post_type=attachment&numberposts=-1');

foreach ($attachments as $att) .... and so on

I then do some stuff to the images to finally create an image slideshow with the images from the pages.

Now the tricky part, I want to exclude the attachments of 2 specific pages in the installatie (client request) and I don't really know how to go about this.

Any wordpress wizards around here?

+1  A: 

Can't you just look at the ID or title of the attachment and skip it? it would be hard coded and not very elegant, but it would work.

A more extensible way would be to assign a tag to the attachment, such as "no-show" and ignore all attachments with this tag.

Byron Whitlock
A: 

Byron's former answer in code :)

$excluded_parents = array(1, 4, 7); // IDs of excluded parent posts

foreach ($attachments as $att) {
    if (in_array($att->post_parent, $excluded_parents))
        continue;

    // carry on coding!
}
TheDeadMedic