Subscribe By RSS or Email

November 3, 2009

Start Using WordPress Attachments Now




  • Buffer



  • Buffer

Check it out: How often have you wanted to add an attachment for a specific post in WordPress? This little snippet of PHP will let you do just that. It loads attachments into an array ($args), and then lists them (foreach...) with their respective titles (the_title).

$args = array(
	'post_type' => 'attachment',
	'numberposts' => null,
	'post_status' => null,
	'post_parent' => $post->ID
);

$attachments = get_posts($args);

if ($attachments) {
	foreach ($attachments as $attachment) {
		echo apply_filters('the_title', $attachment->post_title);
		the_attachment_link($attachment->ID, false);
	}
}



Related Posts Plugin for WordPress, Blogger...

Read more from Blogging
About the author, Derek Land

Derek has been designing & writing since childhood and more recently has designed & developed for international projects, as well as written for several digital magazines. He lives in New York with his family, two cats, and vintage Italian espresso maker. You should follow him on Twitter

On Twitter

We're teaming up with ThriveSolo for a giveaway! We have memberships for ThriveSolo Project Management - FREE. Watch this space for details