多个帖子缩略图$ imgURL

时间:2014-08-18 10:48:27

标签: php wordpress

我有一个带有背景图片的标题,在模板文件中,我需要使用多个后缩略图插件的辅助图像,而不是运行的img。 这是开头的代码:

<?php
if (has_post_thumbnail()) { //if a thumbnail has been set
    $imgID = get_post_thumbnail_id($post->ID); //get the id of the featured image
    $featuredImage = wp_get_attachment_image_src($imgID, 'full' );//get the url of the featured image (returns an array)
    $imgURL = $featuredImage[0]; //get the url of the image out of the array

    ?>
    <style type="text/css">
    .header-image {
        border:none;
        color:black;
        background: url(<?php echo $imgURL ?>) no-repeat center center fixed; 
                -webkit-background-size: cover;
                -moz-background-size: cover;
                -o-background-size: cover;
                background-size: cover;
        min-height:580px;
        display:block;
        position:relative;
        width: 100%;
        overflow: hidden;}
  </style>
<?php
}//end if
?> 

我必须更改$ imgURL并放置一个辅助图像。

我试过了:

<?php
if (has_post_thumbnail()) { //if a thumbnail has been set
    $imgID = get_post_thumbnail_id($post->ID); //get the id of the featured image
    $featuredImage = wp_get_attachment_image_src($imgID, 'full' );//get the url of the featured image (returns an array)
    $imgURL = apply_filters( 'secondary-image', '', array(
'image_size' => 'large'
) );
?>

但它不起作用......有什么想法吗?谢谢

1 个答案:

答案 0 :(得分:3)

尝试使用:

$imgURL = MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image', NULL, 'large');

这将返回具有“大”图像大小的次映像的URL。

仅供参考,如果您需要有关使用多个帖子缩略图插件的更多详细信息,请参阅以下插件的常见问题解答页面:https://github.com/voceconnect/multi-post-thumbnails/wiki/Frequently-Asked-Questions