November 14th, 2009 | Categories: Wordpress | Tags: , , , ,

In WordPress you can add attachments to your posts. Your articles be more interesting and shareable. WordPress have attachment manager and you can manage your attachments wtih this manager. Also you can show your attachments with a template code. Let’s Begin…

Here is the code;

Just copy and paste this code to your theme’s single.php or what your theme use the file to show posts. After that attachments will be shown.

// place inside loop
$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);
	}
}

That’s All. Have a nice day.


No comments yet.