get_attachment_link [ WordPress Function ]
get_attachment_link ( $id = false )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: wp_get_attachment_link, get_the_attachment_link, get_attachment_icon, the_attachment_link, the_attachment_links
Retrieve permalink for attachment.
This can be used in the WordPress Loop or outside of it.
Source
<?php
function get_attachment_link($id = false) {
global $post, $wp_rewrite;
$link = false;
if ( ! $id)
$id = (int) $post->ID;
$object = get_post($id);
if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
$parent = get_post($object->post_parent);
if ( 'page' == $parent->post_type )
$parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
else
$parentlink = get_permalink( $object->post_parent );
if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
$name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
else
$name = $object->post_name;
if ( strpos($parentlink, '?') === false )
$link = user_trailingslashit( trailingslashit($parentlink) . $name );
}
if ( ! $link )
$link = home_url( "/?attachment_id=$id" );
return apply_filters('attachment_link', $link, $id);
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/get attachment link « WordPress Codex
<?php $attachment_id = 1; // ID of attachment $attachment_page = get_attachment_link( $attachment_id ); ?> <a href="<?php echo $ attachment_page; ?> ...
codex.wordpress.org - Function Reference/wp get attachment link « WordPress Codex
Description. Returns an HTML hyperlink to an attachment file or page, containing either. An image at some specified size, for image attachments; or; A media ...
codex.wordpress.org - Function Reference/wp get attachment url « WordPress Codex
If you want a URI for the attachment page, not the attachment file itself, you can use get_attachment_link. Also refer: wp_insert_attachment, wp_upload_dir, ...
codex.wordpress.org - get_attachment_link() WordPress function reference, arguments and ...
get_attachment_link(). Retrieve permalink for attachment. This can be used in the WordPress Loop or outside of it. Signature. get_attachment_link( $id = false ) ...
queryposts.com