2015-12-01 46 views
1

I'm在壁紙博客實際工作,我想提供包含在媒體庫不同,具體尺寸壁紙下載圖像的可能性。提供特定的圖像大小爲下載(牆紙網站)

到現在爲止,我做了以下幾件事:

  • 創建子主題
  • 加入一些額外的牆紙圖像尺寸添加到functions.php
  • 安裝插件「手動圖像裁剪」,讓我裁剪所有可用的圖像大小單獨(鏈接到插件:https://de.wordpress.org/plugins/manual-image-crop/
  • 包括牆紙圖像張貼和選擇「鏈接到附件」
  • addi ng「attachment.php」,帶有一些樣式給我的孩子主題。
  • 加入以下代碼到我這個網站上找到的attachment.php:https://premium.wpmudev.org/blog/advanced-attachment-page/

    <p class='resolutions'> Downloads: 
    <?php 
        $images = array(); 
        $image_sizes = get_intermediate_image_sizes(); 
        array_unshift($image_sizes, 'full'); 
        foreach($image_sizes as $image_size) { 
         $image = wp_get_attachment_image_src(get_the_ID(), $image_size); 
         $name = $image_size . ' (' . $image[1] . 'x' . $image[2] . ')'; 
         $images[] = '<a href="' . $image[0] . '">' . $name . '</a>'; 
        } 
    
        echo implode(' | ', $images); 
    ?> 
    </p> 
    

隨着THI我得到一個很好的附件頁面,預覽圖像鏈接到該圖像的所有尺寸。那已經很好了,但對我來說還不夠好。

我想排除一些圖像尺寸,如「縮略圖」,「中等」,「大」,而且我用的主題中的造型而言一些額外的大小。

有沒有人一個想法如何排除這些大小或者反過來,只選擇所需要下載的大小?

感謝您的任何想法,可能會解決這個問題

回答

0

您可以使用WordPress的這個功能申報圖像的新尺寸: https://developer.wordpress.org/reference/functions/add_image_size/

例:

add_image_size(「大」 ,1200,600); add_image_size( '超大型',2400,1200);

然後你可以使用任何論文的使用的紙型: https://codex.wordpress.org/Function_Reference/the_post_thumbnail

the_post_thumbnail( '超大型');

要重新生成所有的縮略圖,使用重新生成縮略圖插件。

+0

您好,感謝您的回答。 我已經在add_image_size中添加了一些額外的圖像大小,正如我在我的問題中所寫的那樣,我手動裁剪它們以優化它們。 圖像全部在媒體庫中,所有圖像大小的下載鏈接都在附件頁面上工作。 現在我想要排除其中的一些,因爲沒有人需要大小像60x60像素或類似的壁紙。 – Tiburon

0

我找到了解決自己。要僅選擇特定的圖像尺寸,必須在image_sizes數組中指定像這樣的內容:

<?php the_content(); ?> 

      <p class='resolutions'> Downloads: 
      <?php 
        $images = array(); 
        $image_sizes = array ('image1', 'image5', 'image9'); 
        foreach($image_sizes as $image_size) { 
          $image = wp_get_attachment_image_src(get_the_ID(), $image_size); 
          $name = $image_size . ' (' . $image[1] . 'x' . $image[2] . ')'; 
          $images[] = '<a href="' . $image[0] . '">' . $name . '</a>'; 
        } 

        echo implode(' | ', $images); 
      ?>