関数 get_attachment_link()
2015/01/14
関数 get_attachment_link()
定義ファイル :/blog/wp-includes/link-template.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | function get_attachment_link( $post = null, $leavename = false ) { global $wp_rewrite; $link = false; $post = get_post( $post ); $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false; if ( $wp_rewrite->using_permalinks() && $parent ) { if ( 'page' == $parent->post_type ) $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front else $parentlink = get_permalink( $post->post_parent ); if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker else $name = $post->post_name; if ( strpos($parentlink, '?') === false ) $link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' ); if ( ! $leavename ) $link = str_replace( '%postname%', $name, $link ); } if ( ! $link ) $link = home_url( '/?attachment_id=' . $post->ID ); return apply_filters( 'attachment_link', $link, $post->ID ); } |