【发布时间】:2015-07-24 02:29:00
【问题描述】:
请问如何从wordpress媒体中获取wordpress图片的具体title属性?
上传图片时输入的信息,包括生活、标题、替代标题、描述。
【问题讨论】:
请问如何从wordpress媒体中获取wordpress图片的具体title属性?
上传图片时输入的信息,包括生活、标题、替代标题、描述。
【问题讨论】:
这应该对你有帮助。
$title = get_post(get_post_thumbnail_id())->post_title; // Title
$caption = get_post(get_post_thumbnail_id())->post_excerpt; // Caption
$description = get_post(get_post_thumbnail_id())->post_content; // Description
【讨论】:
你可以找到wordpress图片附件的具体属性。
<?php
$attachment_id = 8; // attachment ID
$image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
if( $image_attributes ) {
?>
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
<?php } ?>
An array containing:
[0] => url
[1] => width
[2] => height
[3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.
【讨论】: