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>
<ul>
<?php
$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)) {
?>
<li>
<?php
setup_postdata($post);
the_attachment_link($post->ID, true);
?>
</li>
<?php
}
}
}
?>
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