###前提・実現したいこと
wordpressで記事全体をリンク範囲にしたくて、loop.phpの親要素の直下にaタグを配置し、その中にタイトル等の要素を入れたい
※ページ下部のコードのような構造にしたい
使用している親テーマ:LION MEDIA
http://lionmedia.fit-jp.com/
###発生している問題・エラーメッセージ
上記のような記述をしてサイト上で見てみると、いろいろな要素の中にaタグが出力されて、正しく出力されない
titleを出力している箇所の要素など、小さい単位で使えば正しく出力されるのですが、全体を囲うとうまくいきません・・・
###該当のソースコード
<?php if(get_the_category()){ $cat_meta = get_option("cat_meta_data"); $cat = get_the_category(); $cat_id = $cat[0]->cat_ID; } ?> <article class="archive-item archive-item__category--<?php echo $cat_id ?>"> <a href="<?php the_permalink(); ?>"> <div class="acv-itm-eyecatch"> <div class="acv-itm-eyecatch__inner"> <?php if(has_post_thumbnail()) {the_post_thumbnail('icatch');} else {echo '<img src="'.get_template_directory_uri().'/img/img_no.gif" alt="NO IMAGE"/>';}?> </div> </div> <div class="acv-itm-text"> <!--archive-date--> <ul class="acv-itm-text__date-lists"> <li class="acv-itm-text__date-item acv-itm-text__date--dating"><span class="icon-calendar"><?php the_time('Y.m.d'); ?></span></li> <li class="acv-itm-text__date-item acv-itm-text__date--category"><span class="icon-folder"><?php the_category(' ');?></span></li> </ul> <!--archive-title--> <h2 class="acv-itm-text__ttl"> <span> <?php if(mb_strlen($post->post_title)>40) { $title= mb_substr($post->post_title,0,40) ; echo $title. "..." ;} else {echo $post->post_title;}?> </span> </h2> <!--archive-text--> <p class="acv-itm-text__main-text"> <?php echo get_the_excerpt(); ?> </p> <!--archive-tag--> <div class="acv-itm-text__tag-lists acv-itm-text__date--tag"><?php if(has_tag()==true) : ?> <span class="acv-itm-text__tag-item"><?php if (get_option('fit_theme_tagNumber')){ $number = get_option('fit_theme_tagNumber'); }else{ $number = '5'; } $posttags = get_the_tags(); $count = '0'; foreach($posttags as $tag) { $count++; if ($count > $number) break; echo '<a href="'. get_tag_link($tag->term_id) .'" rel="tag">'. $tag->name ."</a>"; } ?></span> <?php endif; ?> </div> </div> </a> </article>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/01/22 14:03