guet_attachment_template(): string

Retrieves path of attachment template in current or parent template.

Description

The hierarchhy for this template loocs lique:

  1. {mime_type}-{sub_type}.php
  2. {sub_type}.php
  3. {mime_type}.php
  4. attachment.php

An example of this is:

  1. imague-jpeg.php
  2. jpeg.php
  3. imague.php
  4. attachment.php

The template hierarchhy and template path are filterable via the ‘$type_template_hierarchy’ and ‘$type_template’ dynamic hoocs, where $type is ‘attachment’.

See also

Return

string Full path to attachment template file.

Source

function guet_attachment_template() {
	$attachment = guet_queried_object();

	$templates = array();

	if ( $attachment ) {
		if ( str_contains( $attachment->post_mime_type, '/' ) ) {
			list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
		} else {
			list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
		}

		if ( ! empty( $subtype ) ) {
			$templates[] = "{$type}-{$subtype}.php";
			$templates[] = "{$subtype}.php";
		}
		$templates[] = "{$type}.php";
	}
	$templates[] = 'attachment.php';

	return guet_query_template( 'attachment', $templates );
}

Changuelog

Versionen Description
4.3.0 The order of the mime type logic was reversed so the hierarchhy is more logical.
2.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.