WordPress Attachment Tags

Hello Friends,
Today I want to introduce you the cheat code to the wordpress theme.  I want to post with the details about the cheat code. So, it is going to be more big. For the assist of reading, I want to slice my post in the type / category basis. Today, I want to discuss about the Attachment Tags. Tomorrow, I will discuss about the Author Tag.

List of the attachment tags-

Get Attachment Link                          get_attachment_link();
Is Attachment                                       is_attachment();
The Attachment Link                         the_attachment_link();
Attachment Is Image                         wp_attachment_is_image();
Get Attachment Image                      wp_get_attachment_image();
Get Attachment Image Source       wp_get_attachment_image_src();
Get Attachment MetaData                wp_get_attachment_metadata();

Now let me explain about the tags-

get_attachment_link();

Returns the URI of the page for an attachment.
<?php get_attachment_link(id); ?>
id
Type: Integer
The ID of the attachment.

is_attachment();

This Conditional Tag checks if an attachment is being displayed. An attachment is an image or other file uploaded through the post editor’s upload utility. Attachments can be displayed on their own ‘page’ or template. For more information, see Using Image and File Attachments. This is a boolean function, meaning it returns either True or False.

<?php is_attachment(); ?>
No parameters.


the_attachment_link();

Outputs a hyperlink to the attachment file, or Missing Attachment if the attachment can’t be found. The hyperlink contains either (1) a thumbnail or full-size image (as specified), if it exists; or (2) an icon representing the media type of the file, if it exists; or (3) the attachment title (as text).

<?php the_attachment_link(id, fullsize, permalink); ?>
id
Type: Integer
ID of the desired attachment. Optional; defaults to the ID of the current post.


fullsize

Type: Boolean · Default: False

For an image attachment, use the original image (true) or WordPress-generated thumbnail (false). If set to false and the thumbnail can’t be found, the full-size image may be used instead.


permalink

Type: Boolean · Default: False

Link to the attachment page (true) or directly to the file/image (false).

wp_attachment_is_image();

This function determines if a post’s attachment is an image. It returns True if the attachment is an image, False if not.

<?php wp_attachment_is_image($post_id); ?>

&post_id

Type: Integer

Integer ID of the post.

wp_get_attachment_image();

Returns an HTML image element representing an attachment file, if there is any, otherwise an empty string.
<?php echo wp_get_attachment_image($attachment_id, $size, $icon); ?>

$attachment_id

Type: Integer

ID of the desired attachment. Usually required; you can omit it inside a Loop of attachments (such as on an attachment page).


$size

Type: String | Array · Default: Thumbnail

Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32). As of Version 2.5, this parameter does not affect the size of media icons, which are always shown at their original size. Optional.


$icon

Type: Boolean · Default: False

Use a media icon to represent the attachment. Optional.

wp_get_attachment_image();

Returns an HTML image element representing an attachment file, if there is any, otherwise an empty string.

<?php echo wp_get_attachment_image($attachment_id, $size, $icon); ?>

$attachment_id

Type: Integer

ID of the desired attachment. Usually required; you can omit it inside a Loop of attachments (such as on an attachment page).


$size

Type: String | Array · Default: Thumbnail

Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32). As of Version 2.5, this parameter does not affect the size of media icons, which are always shown at their original size. Optional.


$icon

Type: Boolean · Default: False

Use a media icon to represent the attachment. Optional.

wp_get_attachment_image_src();

Returns an image representing an attachment file, if there is any. Else returns False.

<?php wp_get_attachment_image_src($attachment_id, $size, $icon); ?>

$attachment_id

Type: Integer

ID of the desired attachment.


$size

Type: String | Array · Default: Thumbnail

Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32). As of Version 2.5, this parameter does not affect the size of media icons, which are always shown at their original size. Optional.


$icon

Type: Boolean · Default: False

Use a media icon to represent the attachment. Optional.

wp_get_attachment_metadata();

Retrieve attachment meta field for attachment ID. Returns False on failure.

<?php wp_get_attachment_metadata($post_id, $unfiltered) ?>

$post_id

Type: Integer

(Required) ID of the desired attachment.


$unfiltered

Type: Boolean | Array · Default: False

If true, filters are not run.

This is the end of the attachment tag. Hope, this will be helpful for any wordpress theme designer.  My next tutorial about  the Author Tag. Please keep in touch.

Best of luck-

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s