【问题标题】:wordpress Get Image Description for attached imageswordpress 获取附加图像的图像描述
【发布时间】:2013-12-23 09:01:42
【问题描述】:

我正在尝试将帖子分成 2 列。第一列是贴在帖子上的任何图片,右列是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';
    }?>

【问题讨论】:

  • $image 对象类在哪里?必须看到它来帮助你。我会推荐你​​ var_dump($images) 看看它吐出什么。
  • 看起来这个问题也在wordpress.stackexchange上发布了答案。

标签: php wordpress foreach


【解决方案1】:

这是否有助于保持原始格式:大写和空格?

apply_filters( 'the_description' , $image->post_content );

将我的特色图像定位到 nextgen 画廊时,描述 tekst 发生了变化:大写更改(大写/小写等).. 空格和末尾删除点等... 有人吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 2022-07-09
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    相关资源
    最近更新 更多