wordpressで検索結果が1ページに1記事しか表示できないのですが、
(検索数は複数になっているので次ページには行けたりします)
このソースのどこを書き変えれば複数の記事(一覧と同じ記事数、またはsearch.phpで決定)を一覧に表示できますか?
search.phpの内容
php
1<?php get_header(); ?> 2 <h3 class="search">「<?php the_search_query(); ?>」の検索結果 : <?php echo $wp_query->found_posts; ?>件</h3> 3 <?php 4 if (have_posts() && get_search_query()) : 5 while (have_posts()) : 6 the_post(); 7 get_template_part('each_exrpt_post'); 8 endwhile; 9 ?> 10 <div id="post-<?php the_ID(); ?>" class="post img-left clearfix"> 11 <a href="<?php the_permalink() ?>" class="thumbnail"> 12 <?php thumbnail_check($post->ID,'size'); ?> 13 </a> 14 <div class="section"> 15 <h4><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php echo get_the_title(); ?></a></h4> 16 <div class="post-meta"><span class="post-date"><?php echo get_the_date(); ?></span><span class="category"><?php the_category(', ') ?></span></div> 17 <div class="article"> 18 <?php if (is_search()) { 19 the_excerpt(); 20 } else { 21 the_content(); 22 } 23 ?> 24 </div> 25 </div> 26 </div> 27 <?php if ( $wp_query -> max_num_pages > 1 ) : ?> 28 <div class="pager"><?php next_posts_link('« 古い記事'); previous_posts_link('新しい記事 »'); ?></div> 29 <?php endif; ?> 30 <!-- /pager --> 31 <?php else: ?> 32 <div class="section"> 33 <h4>記事はありません</h4> 34 <p>お探しの記事は見つかりませんでした。</p> 35 </div> 36 <?php endif; ?> 37<?php get_sidebar(); ?> 38<?php get_footer(); ?>
ここが問題になっている気がするんですが違いますか?
php
1 <?php 2 if (have_posts() && get_search_query()) : 3 while (have_posts()) : 4 the_post(); 5 get_template_part('each_exrpt_post'); 6 endwhile; 7 ?>
解決していないため、追記します。
ソースは簡略にしたところこういった感じです。
php
1<?php get_header(); ?> 2 <p class="search">「<?php the_search_query(); ?>」の検索結果</p> 3 <?php 4 if (have_posts() && get_search_query()) : 5 while (have_posts()) : 6 the_post(); 7 get_template_part('each_exrpt_post'); 8 endwhile; 9 ?> 10 <div id="post-<?php the_ID(); ?>" class=""> 11 <div class="section"> 12 <h4><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php echo get_the_title(); ?></a></h4> 13 </div> 14 <?php if ( $wp_query -> max_num_pages > 1 ) : ?> 15 <div class="pager"><?php next_posts_link('« 古い記事'); previous_posts_link('新しい記事 »'); ?></div> 16 <?php endif; ?> 17 <!-- /pager --> 18 <?php else: ?> 19 <div class="section"> 20 <p>お探しの記事は見つかりませんでした。</p> 21 </div> 22 <?php endif; ?> 23<?php get_sidebar(); ?> 24<?php get_footer(); ?>
↑search.php
php
1//function.phpに特定の記事を検索結果に出さないように追記 2function fb_search_filter($query) { 3 if ( !$query -> is_admin && $query -> is_search) { 4 $query -> set('post__not_in', array(43, 27, 9, 85, 7, 64, 31, 36, 73, 5,) ); 5 } 6 return $query; 7} 8add_filter( 'pre_get_posts', 'fb_search_filter' );
↑functions.php
すみません、長々となってしまいましたが助言をください。
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/05/11 08:13