記事ページでquery_postsを複数使用してデータを取り込んでいるのですが、
ページを開くのに2秒くらいかかってしまいます。
phpの処理が終わらないとJavaScriptが動作しないのか、
スライドショーもその間動作しないようで2秒間画像が縦並びになります。
query_postsは重くなるから使わない方がいいと良くネット上で書かれていますが、
実際にget postsを使用すると値が直接取れないので、
さらにget_postで値を拾わないといけないのかと思います。
ご相談したいのは、get_postsとget_postで2回データベースにアクセスするのであれば、
対して変わらないのではないかと思うのですがどうなんでしょうか。
(query_postsも2回データベースを読んでいるそうなので)
###現状のソース
<div class="aside"> <?php // レコメンドもどき機能 if($placenum){ $taxquerysp[] = array( 'taxonomy'=>'タクソノミー名', 'terms'=> 'ターム名', 'include_children'=>false, 'field'=>'slug', 'operator'=>'AND' ); } query_posts( array( 'post_type' => "カスタム投稿タイプ名", 'tax_query' => $taxquerysp, 'posts_per_page' => 5, )); if(!empty($wp_query->found_posts)){ // 記事表示のループ if ( have_posts() ) : ?> <div class="aside_mansion aside_mansion_ms mb20"> <p class="check_mansion">近隣物件</p> <?php while ( have_posts() ) : the_post(); ?> <a href="<?php echo get_permalink(); ?>"> <dl> <dt><img src="<?php echo esc_html( $post->gaikan); ?>" alt="" width="153"></dt> <dd class="name"><?php the_title();?></dd><?php if(!empty($post->sale_price_min)|!empty($post->sale_price_max)){; ?> <dd class="price">価格:<span class="strong_orange"><?php echo number_format_i18n((int)$post->sale_price_min/10000)."</span>万円"; ?> - <span class="strong_orange"><?php echo number_format_i18n((int)$post->sale_price_max/10000)."</span>万円"; ?></dd> <?php }; ?><?php if(!empty($post->rent_price_min)|!empty($post->rent_price_max)){; ?> <dd class="price">賃料:<span class="strong_orange"><?php echo number_format_i18n((int)$post->rent_price_min/10000)."</span>万円"; ?> - <span class="strong_orange"><?php echo number_format_i18n((int)$post->rent_price_max/10000)."</span>万円"; ?></dd> <?php }; ?> <dd class="area"><?php echo $post->position ; ?></dd> </dl> </a><br> <?php endwhile; else: endif; wp_reset_query(); } ?> </div> </div><!--aside-->
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/02 07:01
2017/02/02 07:07