Search results display with number of posts& its category with number of post in the category

1) 검색 결과 개수를 세기.
2) 원하는 카테고리에 검색 결과에 맞는 포스트가 몇개인지 표시
3) 카테고리 별로 검색된 포스트들 보이기
4) 디자인

1) Count number of posts in search results and display next to the Search Results title.
검색 결과 개수를 title 에 표시

search.php -> class=”page-title”

$allsearch = new WP_Query("s=$s&showposts=-1"); $count = $allsearch->post_count;
printf( __( 'Search Results for: %s (%u) 
', 'twentytwelve' ), '' . get_search_query() . '', $count );

2) Display a certain categories, counts the posts in the categories.
3) Make a link to show the search results in each category.

After the title part in search.php

$url_computer = get_bloginfo('url');
$url_computer = esc_attr(add_query_arg(array( 'category_name' => 'computer', 's' => get_search_query()), $url_computer));
$q_computer = new WP_Query( array( 'category_name' => 'computer', 's' => get_search_query()) ); 
$count_computer = $q_computer ->found_posts;
echo "<a href="$url_computer" rel="nofollow">Computer($count_computer)</a>";
echo "&nbsp &nbsp";

4) add css

.search .page-title{	 	 
 font-size:20px;	 	 
}	 	 

Leave a Reply