內容簡介
這個外掛提供了樣板標籤 wp_get_post_image()。 使用它來呼叫透過 WordPress 媒體上傳程式動態建立的圖片。
注意:此外掛只適用於 WordPress 開發人員和佈景主題建立者。
用法
<?php wp_get_post_image($args); ?>
預設用法
<?php $args = array(
'width' => null,
'height' => null,
'css' => '',
'parent_id' => '',
'post_id' => '',
'filename' => '',
'return_html' => true
); ?>
預設情況下,此函式會返回:
最後上傳的圖片,外面包裹著圖片標籤 (<img />)。
等比例縮放的圖片,width最大不大於200px。
指定CSS類別wp-image-*ID*而沒有其他類別。
如果您透過css新增thickbox,將為 Thickbox 兼容性新增適當的錨點<a>標籤。
參數
width (integer) – 圖片的寬度。
height (integer) – 圖片的高度。
parent_id (integer) – 附加檔案的post_parent 的ID。指定parent_id將依據menu_order回傳第一個附加到父文章的圖片。
post_id (integer) – 附檔案的ID。
filename (string) – 對應於附檔案的post_name的檔名。
return_html (boolean) – true 返回將圖片包裝在 XHTML 圖片標籤中。 false 則返回圖片的URL。
範例
<?php
//在任何您可以存取$post->ID的地方(例如WordPress循環)中使用此範例
if(function_exists('wp_get_post_image'))
echo wp_get_post_image('width=450&css=alignleft&parent_id='.$post->ID);
?>
外掛標籤
開發者團隊
📦 歷史版本下載
原文外掛簡介
This plugin provides the template tag wp_get_post_image(). Use it to call dynamically created images uploaded via the WordPress media uploader.
NOTE: This plugin is intended for use by WordPress developers and theme builders only.
Usage
Default Usage
null,
'height' => null,
'css' => '',
'parent_id' => '',
'post_id' => '',
'filename' => '',
'return_html' => true
); ?>
By default, the function returns:
The last uploaded image wrapped in an image tag ().
A proportionately sized image with a width no greater than 200px.
The CSS class wp-image-*ID* and no other classes.
If you add thickbox via css, the appropriate anchor tag will be added for Thickbox compatibility.
Parameters
width (integer) – Width of image.
height (integer) – Height of image.
parent_id (integer) – The ID of the post_parent for the attachment. Specifying the parent_id returns the first image attached to the parent post according to menu_order.
post_id (integer) – The ID of the attachment.
filename (string) – The filename that corresponds to the post_name of the attachment.
return_html (boolean) – true returns the image wrapped in an XHTML image tag. false returns the image’s URL.
Example
ID, e.g. the WordPress loop
if(function_exists('wp_get_post_image'))
echo wp_get_post_image('width=450&css=alignleft&parent_id='.$post->ID);
?>
