Posted by KaiseRCrazY on 14th November 2009

Show Post Attachments!

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.

  • del.icio.us
  • Digg
  • Facebook
  • FriendFeed
  • Reddit
  • StumbleUpon
  • Technorati
  • PDF
  • Print

No comments yet!

Post your comments