【EASEL】作品タイプ「文章」一覧表示のアイキャッチ画像にリンクを設定する

作品タイプ「文章」を一覧表示した際に、デフォルトでは作品のタイトルのみにリンクが設定されています。

アイキャッチを設定している場合に、アイキャッチ画像を押した際にも作品ページに飛べるようにカスタマイズします。

 

PHPの編集

「taxonomy-custom_tag」と、「library」→「parts」→「works-text」を編集します。※編集前にバックアップを取ってください。

 

編集前

<?php if ( has_post_thumbnail() ) : ?>
<figure class="eye-catch" itemprop="image" itemscope itemtype="https://schema.org/ImageObject">
<?php
    $thumbnail_id = get_post_thumbnail_id();
    $eye_img = wp_get_attachment_image_src( $thumbnail_id , 'full' );
    $url = $eye_img[0];
    $width = $eye_img[1];
    $height = $eye_img[2];
    $size = $width.'x'.$height.' size-'.$width.'x'.$height;
    $attr = array(
        'class' => "attachment-$size eye-catch-image",
    );
    //アイキャッチの表示
    if ($width && $height) {
        the_post_thumbnail(array($width, $height), $attr);
    } else {
        the_post_thumbnail('full', $attr);
    }
?>
</figure>
<?php endif; ?>

2つのファイルに同じ記述があります。以下のように書き足します。

 

編集後

<?php if ( has_post_thumbnail() ) : ?> 
<figure class="eye-catch" itemprop="image" itemscope itemtype="https://schema.org/ImageObject"> 
<a href="<?php the_permalink(); ?>" rel="bookmark"> 
<?php 
    $thumbnail_id = get_post_thumbnail_id(); 
    $eye_img = wp_get_attachment_image_src( $thumbnail_id , 'full' ); 
    $url = $eye_img[0]; 
    $width = $eye_img[1]; 
    $height = $eye_img[2]; 
    $size = $width.'x'.$height.' size-'.$width.'x'.$height; 
    $attr = array( 
       'class' => "attachment-$size eye-catch-image",     ); 
    //アイキャッチの表示 
    if ($width && $height) { 
        the_post_thumbnail(array($width, $height), $attr); 
    } else { 
        the_post_thumbnail('full', $attr); 
    } 
?> 
</a> 
</figure> 
<?php endif; ?>

<figure>と<?php…>の間に<a href=…>を追加し、アイキャッチ画像にリンクを設定しました。

 

一覧表示でリンクを設定するだけなら「works-text」だけ変更でも大丈夫ですが、タグ一覧表示の際にもリンクを設定したかったため「taxonomy-custom_tag」も同様に編集しました。