特色帖子上的大图像,单个帖子上的普通图像

时间:2012-10-02 作者:vajrasar

我已经包含了一个代码,它可以获取我的类别=featured下的任何帖子。这会出现在我博客页面的内容顶部(*每当我们有突发新闻要显示*)。

问题是,我可以在单个帖子上显示的图像的宽度是750px,而我有足够的空间在主页(*blog page*)上显示的帖子上显示1100px的图像。

所以我想嵌入一个选项,可以上传两幅图像(*750px和1100px*)。然后我应该能够在博客页面上显示文章时使用1100px的图像,在用户单击并转到单个文章时使用750px的图像。

是否可能,以及如何实现?谢谢

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

通过在通话时指定图像的大小,您可以很容易地以多种大小显示特色图像,但如果您希望它们不同,可以使用此插件中的代码:

http://wordpress.org/extend/plugins/multiple-featured-images/

以下是教程:

http://lifeonlars.com/wordpress/how-to-add-multiple-featured-images-in-wordpress/

e、 g.注册示例:

if (class_exists(\'MultiPostThumbnails\') {
    if (MultiPostThumbnails::has_post_thumbnail(\'folio\', \'feature-image-2\')) {
        MultiPostThumbnails::the_post_thumbnail(\'folio\', \'feature-image-2\'); 
    }
    if (MultiPostThumbnails::has_post_thumbnail(\'folio\', \'feature-image-3\')) {
        MultiPostThumbnails::the_post_thumbnail(\'folio\', \'feature-image-3\'); 
    }
    if (MultiPostThumbnails::has_post_thumbnail(\'folio\', \'feature-image-3\')) {
        MultiPostThumbnails::the_post_thumbnail(\'folio\', \'feature-image-3\'); 
    }
}
示例用法:

<div id="slider">          
    <?php    
        // Checks if post has a feature image, grabs the feature-image and outputs that along with thumbnail SRC as a REL attribute 
        if (has_post_thumbnail()) { // checks if post has a featured image and then outputs it.     
            $image_id = get_post_thumbnail_id ($post->ID );  
            $image_thumb_url = wp_get_attachment_image_src( $image_id,\'small-thumb\');                               
            $attr = array(
                \'class\' => "folio-sample",                                   
                \'rel\' => $image_thumb_url[0], // REL attribute is used to show thumbnails in the Nivo slider, can be skipped if you don\'t want thumbs or using other slider
            );
            the_post_thumbnail (\'feature-image\', $attr);                                            
        }
        if (class_exists(\'MultiPostThumbnails\')) {                              
        // Loops through each feature image and grabs thumbnail URL
        $i=1;
            while ($i<=5) {
                $image_name = \'feature-image-\'.$i;  // sets image name as feature-image-1, feature-image-2 etc.
                if (MultiPostThumbnails::has_post_thumbnail(\'folio\', $image_name)) { 
                    $image_id = MultiPostThumbnails::get_post_thumbnail_id( \'folio\', $image_name, $post->ID );  // use the MultiPostThumbnails to get the image ID
                    $image_thumb_url = wp_get_attachment_image_src( $image_id,\'small-thumb\');  // define thumb src based on image ID
                    $image_feature_url = wp_get_attachment_image_src( $image_id,\'feature-image\' ); // define full size src based on image ID
                    $attr = array(
                        \'class\' => "folio-sample",      // set custom class
                        \'rel\' => $image_thumb_url[0],   // sets the url for the image thumbnails size
                        \'src\' => $image_feature_url[0], // sets the url for the full image size 
                    );                                                                                      
                    // Use wp_get_attachment_image instead of standard MultiPostThumbnails to be able to tweak attributes
                    $image = wp_get_attachment_image( $image_id, \'feature-image\', false, $attr );                     
                    echo $image;
                }                           
                $i++;
            }                            

        }; // end if MultiPostThumbnails 
     ?>
</div><!-- end #slider -->

结束

相关推荐

images within style sheet

我希望有人能在这方面帮助我,因为这已经开始让我抓狂了。我已经搜索了好几个小时,想找到一种在我的样式表中放置图像路径的方法,但一直没有找到。路径不能是绝对路径或“主题相关”路径。解决问题的唯一方法是在html文件中添加以下内容:<style type=\"text/css\"> #menu .menu-drop .menu-label { background: url(<?php echo get_template_directory_uri().