_wp_get_attachment_relative_path

函式
_wp_get_attachment_relative_path ( $file )
Access
Private
引數
  • (string) $file Attachment file name.
    Required:
返回值
  • (string) Attachment path relative to the upload directory.
定義位置
相關方法
wp_get_attachment_metadatawp_get_attachment_urlwp_get_attachment_linkwp_get_attachment_captionwp_get_attachment_image
引入
4.4.1
棄用
-

_wp_get_attachment_relative_path: 這是一個WordPress的函式,用來檢索附件檔案的相對路徑,也就是檔案相對於WordPress內容目錄的路徑: 這個函式對檢索圖片或其他附件檔案的路徑很有用,以便在HTML圖片標籤或其他元素中使用它。

獲得相對於上傳目錄的附件路徑。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _wp_get_attachment_relative_path( $file ) {
$dirname = dirname( $file );
if ( '.' === $dirname ) {
return '';
}
if ( false !== strpos( $dirname, 'wp-content/uploads' ) ) {
// Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
$dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 );
$dirname = ltrim( $dirname, '/' );
}
return $dirname;
}
function _wp_get_attachment_relative_path( $file ) { $dirname = dirname( $file ); if ( '.' === $dirname ) { return ''; } if ( false !== strpos( $dirname, 'wp-content/uploads' ) ) { // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads). $dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 ); $dirname = ltrim( $dirname, '/' ); } return $dirname; }
function _wp_get_attachment_relative_path( $file ) {
	$dirname = dirname( $file );

	if ( '.' === $dirname ) {
		return '';
	}

	if ( false !== strpos( $dirname, 'wp-content/uploads' ) ) {
		// Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
		$dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 );
		$dirname = ltrim( $dirname, '/' );
	}

	return $dirname;
}

常見問題

FAQs
檢視更多 >