How to display attachment and post? (2 posts)

  1. takien
    Posted 7 years ago #

    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 http://wordpress.org/support/topic/233012?replies=4#post-952800,

    <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

  2. takien
    Posted 7 years ago #

    hi.. anyone?

Topic Closed

This topic has been closed to new replies.

About this Topic