Support » Plugins » How to display attachment and post?

  • Hi, some of my post contains image attachment and some not.

    I want to display 10 recent post with attachment in front page.

    I use WP_Query and when my latest 10 posts don’t have attachment, the 10 recent post with attachment is blank.

    i found a code from,

    <li><h2>Recent Attachments</h2>
    $valid_ext = array("pdf", "doc", "rtf", "zip");
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => -1,
    	'post_status' => null,
    	'post_parent' => null, // any parent
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $post) {
    $ext = getFileExt(wp_get_attachment_url($post->ID, false));
    if(in_array($ext, $valid_ext)) {
    	the_attachment_link($post->ID, true);

    ok, it’s work display the attachment, but not the post (like title, excerpt, etc).

    anyone have solution for this?
    sorry about my english. thx

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to display attachment and post?’ is closed to new replies.