是否将特色图像(仅限img url)显示为img源?

时间:2012-02-27 作者:iCeR

我有以下代码:

if (themedy_get_option(\'product_gallery\')) { add_action(\'genesis_post_content\', \'themedy_product_images\', 1); }
function themedy_product_images() { ?>
    <?php 
    global $post;
    $images = get_children( array( \'post_parent\' => $post->ID, \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'numberposts\' => 999, \'order\'=> \'ASC\', \'orderby\' => \'menu_order\' ) ); 
    if ( $images ) { ?>
<div class="twocol-one">
<?php echo get_the_post_thumbnail( $post->ID, \'product-400x600\' ); ?>
    <div class="product_images">
        <div class="container">
            <?php
            foreach ( $images as $image ){
                $gallery_image_info = wp_get_attachment_image_src( $image->ID, \'full\' );
                $gallery_image = $gallery_image_info[0];

                $gallery_thumb_info = wp_get_attachment_image_src( $image->ID, \'Gallery Thumb\' );
                $gallery_thumb = $gallery_thumb_info[0];

                $gallery_image_alt = get_post_meta($image->ID, \'_wp_attachment_image_alt\', true) ? trim(strip_tags( get_post_meta($image->ID, \'_wp_attachment_image_alt\', true) )) : trim(strip_tags( $image->post_title ));

                echo \'<a href="\'.$gallery_image.\'" title="\'.$gallery_image_alt.\'" class="fancybox" rel="single-gallery"><img src="\' . $gallery_thumb . \'" /></a>\';
            }
            ?>
        </div>
    </div>
</div>
问题#1:其中说明:

<?php echo get_the_post_thumbnail( $post->ID, \'product-400x600\' ); ?>
我需要它告诉我

<a id="product" class="MagicZoomPlus" href=" <?php echo get_the_post_thumbnail( $post->ID, \'large\' ); ?> " rel="selectors-class: Active"><img src=" <?php echo get_the_post_thumbnail( $post->ID, \'product-400x600\' ); ?> " alt="" /></a>`
在回显图像的地方(大且产品为400x600),我需要它只回显img url,而不需要它附带的所有其他html。如何修复我的上述代码,使其以我所需的方式呈现?

问题#2:其中说明:

echo \'<a href="\'.$gallery_image.\'" title="\'.$gallery_image_alt.\'" class="fancybox" rel="single-gallery"><img src="\' . $gallery_thumb . \'" /></a>\';
这是该图库中所有其他图像的循环。对于循环中的每个图像<我需要它告诉我

<a class="Selector" href="<?php echo get_the_post_thumbnail( $post->ID, \'large\' ); ?>" rel="zoom-id:product" rev="<?php echo get_the_post_thumbnail( $post->ID, \'medium\' ); ?>"><img src="\' . $gallery_thumb . \'" alt="" /></a>
同样,与#1的问题相同,我需要它只回显图像url/src。

其工作方式如下例所示:http://www.magictoolbox.com/magiczoomplus/

提前感谢您!

Edit

根据布莱恩的建议,我第一次尝试以下特色图片,效果很好!

<?php
    $image = wp_get_attachment_image_src(get_post_thumbnail_id(), \'full\');
    $image2 = wp_get_attachment_image_src(get_post_thumbnail_id(), \'product-400x600\');
?>
<?php echo \'<a id="product" class="MagicZoomPlus" href="\'.$image[0].\'" rel="selectors-class: Active"><img src="\'.$image2[0].\'" alt="" /></a>\'; ?>

Now the question is, how do I go about this for the image gallery items?

1 个回复
最合适的回答,由SO网友:Brian Fegter 整理而成

以下是您需要了解的功能:

示例SAN大小:

echo wp_get_attachment_url(get_post_thumbnail_id());
尺寸示例:

$image = wp_get_attachment_image_src(get_post_thumbnail_id(), \'large\');
echo $image[0]; //as HREF in your A tag
您可以按如下方式获取所有库图像:

$args = array(
    \'order\'=> \'ASC\',
    \'post_mime_type\' => \'image\',
    \'post_parent\' => $post->ID,
    \'post_type\' => \'attachment\'
);

$attachments = get_children( $args );

foreach($attachments as $attachment){
    //use $attachment->ID to retrieve attachment information
    $image = wp_get_attachment_image_src($attachment->ID, \'large\');
}

结束

相关推荐

Images not showing on blog

今天早上我wordpress博客上的大部分图片(http://records.photodharma.net)已停止加载。这甚至发生在嵌入式系统上。此处嵌入的所有图像:http://records.photodharma.net/photos/chiang-mai-photo-albums-of-modern-structures 当我在Firebug中查看它们时,它们会出现,但不会出现在页面上。有几次我看到图像加载后不久就消失了,所以它们似乎试图加载,但被阻止了。我做了一些搜索,并尝试了各种方法,如更新