0

我正在使用自定义帖子类型插件,该插件返回上传文件的附件 ID 而不是其 url。我已经能够使用 wp_get_attachment_image_src 来显示图像,如http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src中所述,但我的问题是让它与模板页面上的代码很好地配合使用从自定义帖子类型调用信息。

将其剥离为基础,这就是从模板页面调用自定义帖子类型信息的内容:

<?php 
    $slideshowplatform = get_post_meta($post->ID, 'slideshowplatform', true);
    foreach($slideshowplatform as $slide) {
        echo '<img src="' . $slide['slide'] . '" />';
    }
?>

我很难将其与法典提供的内容相协调:

<?php 
    $attachment_id = 8; // attachment ID
    $image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
?>

<img src="<?php echo $image_attributes[0]; ?>">

看起来像下面这样的东西应该可以工作,但我显然错过了 php 语法的一些东西

<?php 
    $slideshowplatform = get_post_meta($post->ID, 'slideshowplatform', true);
    foreach($slideshowplatform as $slide) {
        $image_attributes = wp_get_attachment_image_src( $slide['slide'] );
        echo '<img src="<?php echo $image_attributes[0]; ?>" />';
    }
 ?>

任何想法将不胜感激,谢谢。

4

1 回答 1

0

我想这就是你想要的

if ( $post->post_type == 'slideshowplatform' && $post->post_status == 'publish' )
{
    $attachments = get_posts(array(
        'post_type' => 'attachment',
        'posts_per_page' => -1,
        'post_parent' => $post->ID,
        'exclude'     => get_post_thumbnail_id()
    ));

    if ($attachments) {
        foreach ($attachments as $attachment) {
            $thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail-size', true );
            echo $thumbimg;
            //$image_attributes = wp_get_attachment_image_src( $slide['slide'] ); 
            //echo '<img src="' . $image_attributes[0] . '" />';
        }

    }
}
于 2012-06-25T17:27:32.387 回答