Search Results
The ‘search.php’ is the PHP file that is used to display the search results returned from the search form described above. This is not a template as defined by WordPress per se, but is created on the fly when performing a search using the ‘search.php’ file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | <?php get_header(); ?> <div id=“primary”> <div id=“content” role=“main”> <header class=“page-header”> <div class=“post-headline”><h1>Search Results</h1></div> </header> <?php echo ‘<h2 class = “pagetitle”>Search Results for ‘; echo ‘<span class=“search-terms”>“’ . wp_specialchars( get_query_var( ‘s’ ), 1 ) . ‘”</span>’; echo ‘</h2>’; echo ‘<p>’; echo ‘There’ . ( ( 1 === (int) $wp_query->found_posts ) ? ’ was’ : ’ were’ ) . ’ ’ . $wp_query->found_posts . ’ total search result’ . ( ( 1 === (int) $wp_query->found_posts ) ? ” : ‘s’ ); echo ’ found’; if ( ( ‘1’ === $_GET[ ‘exact’ ] ) || ( ‘1’ === $_GET[ ‘sentence’ ] ) ) { echo ’ by’; if ( ‘1’ === $_GET[ ‘exact’ ] ) { echo ’ exact match’; } if ( ( ‘1’ === $_GET[ ‘exact’ ] ) && ( ‘1’ === $_GET[ ‘sentence’ ] ) ) { echo ’ and’; } if ( ‘1’ === $_GET[ ‘sentence’ ] ) { echo ’ phrase’; } } echo ’ in’; if ( array( ‘0’ ) === $_GET[ ‘cat’ ] ) { echo ’ all categories’; } else { echo ’ only the’; avp_search_display_tags( ‘id’, $_GET[ ‘cat’ ], ‘category’ ); echo ( ( 1 === count( $_GET[ ‘cat’ ] ) ) ? ’ category’ : ’ categories’ ); } if ( array( ” ) !== $_GET[ ‘tag’ ] ) { echo ’ with the’; avp_search_display_tags( ‘slug’, $_GET[ ‘tag’ ], ‘post_tag’ ); echo ( ( 1 === count( $_GET[ ‘tag’ ] ) ) ? ’ tag’ : ’ tags’ ); } echo ’ within’; if ( ‘any’ == $_GET[ ‘post_type’ ] ) { echo ’ all published Posts and Pages’; } else if ( ‘page’ == $_GET[ ‘post_type’ ] ) { echo ’ only the published Pages’; } else if ( ‘post’ == $_GET[ ‘post_type’ ] ) { echo ’ only the published Post pages’; } echo ‘.</p>’; /* If there are any posts: */ if ( have_posts() ) { while ( have_posts() ) { the_post(); /* Post Container starts here */ if ( function_exists( ‘post_class’ ) ) { echo ‘<div ‘; if ( is_page() ) { post_class( ‘post’ ); } else { post_class(); } echo ‘id=“post-’ . the_ID() . ’ ”>’; } else { echo ‘<div class=“ ‘ . ( is_page() ? ‘page ’ : ” ) . ‘post” id=“post-’ . the_ID() . ’ ”>’; } echo ‘</div> <!– / Post –>’; } /* END of: If there are any posts */ } ?> </div><!– #content –> </div><!– #primary –> <?php get_sidebar(); get_footer(); ?> |
The most significant modification to the ‘search.php’ form is the reporting of the result count and the search parameters, which really should be standard when reporting the results of any search.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function avp_search_display_tags( $field, $values, $taxonomy ) { $count = 0; foreach ( $values as $value ) { $var = get_term_by( $field, $value, $taxonomy ); echo ’ ’ . $var->name; ++ $count; if ( $count <= ( count( $values ) - 2 ) ) echo ‘,’; else if ( $count == ( count( $values ) - 1 ) ) echo ’ and’; } } ?> |
The ‘avp_search_display_tags()’ function turns the list of categories or tags in a well-ordered list with comma delimiters.
The short URL of the present article is: http://www.terryobrien.me/cnu2p
Personal Links