• Hello everyone!

    I’ve this code in all my pages:

    <ul>
        <?php
            $args = array(
              'post_type' => 'attachment',
              'post_mime_type' => 'application/pdf,application/msword',
              'numberposts' => -1,
              'post_status' => null,
              'post_parent' => $post->ID,
              'orderby' => 'menu_order',
              'order' => 'desc'
              );
            $attachments = get_posts($args);
            if ($attachments) {
              foreach ($attachments as $attachment) {
                echo '<li><a href="'.wp_get_attachment_url($attachment->ID).'">';
                echo $attachment->post_title;
                echo '</a></li>';
              }
            }
        ?>
        </ul>

    It works perfectly but i didn’t succeeded in hiding the output list in pages which don’t have attachments.
    So, is there a function like If post have attachments?

    Thanks to everyone in advance

  • The topic ‘Attachments conditional php’ is closed to new replies.