如何在href标签中获取wordpress特色图像

时间:2014-03-12 12:01:51

标签: php html wordpress

我创建了一个自定义帖子类型,它通过插件弹出。 但是图像没有显示在弹出窗口中,所以我想在href标签中调用图像,我不知道如何调用它。

有一些代码

<?php
    $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title"" rel="lightbox" href="#" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;
    ?>

4 个答案:

答案 0 :(得分:2)

<?php 
    $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title"" rel="lightbox" href="'.$large_image_url[0].'" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;
?>

替换此代码。

答案 1 :(得分:0)

我觉得你应该尝试

$imageUrl = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
<img src="<?php echo $imageUrl; ?>" />

答案 2 :(得分:0)

使用 wp_get_attachment_image_src 获取图片网址

<?php 
 $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 

    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title="" rel="lightbox" href="$image" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;

?>

答案 3 :(得分:0)

你的title标签可能吗?

title""更改为title=""

<?php
    $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title="" rel="lightbox" href="#" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;
    ?>