get_attachment_template

Definition:
function get_attachment_template() {}

Retrieve path of attachment template in current or parent template.
The attachment path first checks if the first part of the mime type exists. The second check is for the second part of the mime type. The last check is for both types separated by an underscore. If neither are found then the file ‘attachment.php’ is checked and returned.

Source code

function get_attachment_template() {

	global $posts;

	$type = explode('/', $posts[0]->post_mime_type);

	if ( $template = get_query_template($type[0]) )

		return $template;

	elseif ( $template = get_query_template($type[1]) )

		return $template;

	elseif ( $template = get_query_template("$type[0]_$type[1]") )

		return $template;

	else

		return get_query_template('attachment');

}

1164

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: