前提・実現したいこと
wordpressでキュレーションサイトを構築しました。
bxslider(js)を使用して、記事のアイキャッチを読み込んでトップページにスライドショーとして表示しております。
サイト制作当時は特に問題がなかったのですが、記事のボリュームが増えるにつれてトップページの表示が遅くなり、読み込みに20秒ほどかかってしまうこともあります。
当初はサイトの表示が遅い理由がわからなかったのですが、トップページに読み込んでいる写真データの数がかなり多いらしい...ということはわかってきました。
表示がものすごく遅い理由はおそらく条件の記述の間違いではないかと考えています。
今までサイトへ投稿したイメージデータを全て読み込んでいるから遅いのかもしれません。
最新記事からスライドに表示するにしても、サイト全体の記事を読み込むのではなく、投稿日の近い記事(20記事ほど)からアイキャッチを表示したいと思っております。
発生している問題・エラーメッセージ
トップページの表示が遅い。読み込みに20秒ほどかかってしまうこともあります。
該当のソースコード
php
1<div class="slider"> 2 <ul> 3<?php 4$num = 0; 5$args = array( 6 'post_type' => array('post'), 7 'post_status' => 'publish', 8 'post-recom' => 'slide', 9 'posts_per_page' => -1 10); 11$postData = get_posts($args); 12$last = count($postData); 13$current = 0; 14foreach ($postData as $post ) : setup_postdata( $post ); 15 ++$current; 16 ++$num; 17 if ($num == 4) { 18 $num = 1; 19 } 20 $thumb_id = get_post_thumbnail_id( $p->id ); 21 if ($thumb_id) { 22 $img = wp_get_attachment_image_src( $thumb_id, 'large' ); 23 } 24 else { 25 26 } 27 $categories = get_the_category(); 28 $cat = $categories[0]; 29?> 30 <?php if ($num == 1) : ?><li class="clearfix"><div class="slide-left"><?php endif; ?> 31 <a class="num<?php echo $num; ?>" href="<?php the_permalink(); ?>"> 32 <strong><?php echo $cat->name;?></strong> 33 <div class="clearfix"> 34 <div class="img" style="background-image:url(<?php echo $img[0]; ?>)"></div> 35 <div class="txt"><p><small><?php the_time( 'Y.m.d' ); ?></small><span><?php the_title(); ?></span></p><?php the_excerpt(); ?></div></div> 36 </a> 37 <?php if ($num == 1) : ?></div><div class="slide-right"><?php endif; ?> 38 <?php if ($num == 3 || $current == $last) : ?></div></li><?php endif; ?> 39<?php endforeach; wp_reset_postdata();?> 40 </ul> 41</div>
回答1件
あなたの回答
tips
プレビュー