我想把帖子分成两列。第一个和左边的是帖子里的任何图片,第二个和右边的是the_content()
(不包括图像)。
所以到目前为止,我没有问题拉所有的图像。然而,我似乎无法获得图像标题或标题或描述。
这是我的密码:
<?php if ( $images = get_posts(array(
\'post_parent\' => $post->ID,
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'post_mime_type\' => \'image\',
)))
{
foreach( $images as $image ) {
$attachmenturl = wp_get_attachment_url($image->ID);
$attachmentimage = wp_get_attachment_image_src( $image->ID, full );
$imageDescription = apply_filters( \'the_description\' , $image->post_content );
$imageTitle = apply_filters( \'the_title\' , $image->post_title );
$i++;
if (!empty($imageTitle)) {
echo \'<div class="client-img-item ci-\'.$count++.\'"><img src="\' . $attachmentimage[0] . \'" alt="\'.$imageTitle.\'" /> <div class="CAPS client-img-caption"><span class="red arrow-lrg">»</span> \'.$imageDescription.\'</div></div><div class="sml-dots"></div>\';
} else { echo \'<img src="\' . $attachmentimage[0] . \'" alt="" />\' ; }
}
} else {
echo \'No Image Found\';
}?>
最合适的回答,由SO网友:Dylan Hildenbrand 整理而成
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
\'alt\' => get_post_meta( $attachment->ID, \'_wp_attachment_image_alt\', true ),
\'caption\' => $attachment->post_excerpt,
\'description\' => $attachment->post_content,
\'href\' => get_permalink( $attachment->ID ),
\'src\' => $attachment->guid,
\'title\' => $attachment->post_title
);
}
Source
像
sporkme explains 在后面的线程中,这将被转储到
functions.php 然后可以调用
$attachment_meta = wp_get_attachment(your_attachment_id);
.