【问题标题】:Different size thumbnail to custom category自定义类别的不同尺寸缩略图
【发布时间】:2013-10-11 20:57:39
【问题描述】:

我想在索引中为自定义类别设置不同大小的缩略图。但是如果帖子有两个或更多类别怎么办?

【问题讨论】:

  • 显示一些代码。你有什么尝试。你想达到什么目的
  • if(is_category( array( 4, 'category-slug', 'My category' ))) : $my_thumbnail = 'thumbnailsize1'; else: $my_thumbnail = 'thumbnailsize2'; endif;

标签: wordpress thumbnails categories


【解决方案1】:

您会想要为帖子(或自定义帖子)添加图像大小 (set_post_thumbnail_size),然后您会想要使用它。根据您要完成的工作,您可能会使用不同的页面来呈现该类别的帖子列表。退房:

http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display

【讨论】:

    【解决方案2】:
     function pr_setup() {
    
            add_image_size( 'thumb1', 132, 64 ); // 132 is width , 64 is height 
    
            add_image_size( 'thumb2',400, 300);
    
        }
    
        add_action( 'after_setup_theme', 'pr_setup' );
    
        if(is_category( array( 4, 'category-slug', 'My category' ))) :
    
          $my_thumbnail = get_the_post_thumbnail('thumb1'); 
       else:
          $my_thumbnail = get_the_post_thumbnail('thumb2'); 
        endif;
    

    在 codex 上了解有关 add_image_size 的更多信息!

    【讨论】:

    • 图片尺寸已经添加,不知道如何根据类别更改。
    【解决方案3】:

    我刚刚完成,我做了这样的事情:

    $category_id = get_cat_ID('My category');
        if ( in_category($category_id) ) :
            $thumb = 'thumbnailsize1';
        else :
            $thumb = 'thumbnailsize2';
        endif;
    

    我认为它有效:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 2013-07-21
      • 1970-01-01
      • 2019-11-29
      • 2011-04-03
      • 2013-11-21
      • 2018-06-21
      相关资源
      最近更新 更多