-
Notifications
You must be signed in to change notification settings - Fork 63
Functions and Template Tags
Chris Scott edited this page Mar 27, 2017
·
2 revisions
For advanced themes and usage, the following functions may prove useful.
Function signature:
MultiPostThumbnails::get_post_thumbnail_id(
$post_type,
$id,
$post_id
)
Get the WordPress post ID of the thumbnail attachment.
-
$post_type
required: The post type of the post the thumbnail is set on. -
$id
required: The id used to register the thumbnail. -
$post_id
required: The post ID of the post the thumbnail is set on.
Function signature:
MultiPostThumbnails::get_post_thumbnail_url(
$post_type,
$id,
$post_id = 0,
$size = null
)
Get the URL of the thumbnail.
-
$post_type
required: The post type of the post the thumbnail is set on. -
$id
required: The id used to register the thumbnail. -
$post_id
optional: The post ID of the post the thumbnail is set on. Defaults to the post ID of the currently queried object. -
$size
optional: The size to use. Defaults to the original size.
Function signature:
MultiPostThumbnails::the_post_thumbnail(
$post_type,
$thumb_id,
$post_id = null,
$size = 'post-thumbnail',
$attr = '' ,
$link_to_original = false
)
Echo the post thumbnail.
-
$post_type
required The post type of the thumbnail being retrieved. If used in the loop,get_post_type()
can be used to prevent hard coding the post type. -
$id
required The id used to register the thubmnail (from the step above). -
$post_id
optional: The Post ID of the post to get the thumbnail for. The currently queried post's ID will be used if not provided. -
$size
optional: Image size to display. Defaults to 'post-thumbnail', which a theme sets usingset_post_thumbnail_size( $width, $height, $crop_flag )
. Or, custom image sizes registered withadd_image_size()
can be used. -
$attr
optional: Passed towp_get_attachment_image()
. Specified as a query string or array of attributes. -
$link_to_original
optional: Wrap link to original image around thumbnail?
Function signature:
MultiPostThumbnails::get_the_post_thumbnail(
$post_type,
$thumb_id,
$post_id = null,
$size = 'post-thumbnail',
$attr = '' ,
$link_to_original = false
)
Get the thumbnail but don't echo it. This uses the same arguments as
MultiPostThumbnails::the_post_thumbnail()
as detailed above.
Function signature:
MultiPostThumbnails::has_post_thumbnail(
$post_type,
$id,
$post_id = null
)
Does the post have the specified thumbnail?
-
$post_type
required: The post type of the post the thumbnail is set on. -
$id
required: The id used to register the thumbnail. -
$post_id
optional: The post ID of the post the thumbnail is set on. Defaults to the post ID of the currently queried object.