すみません、調べても出てこなかったものでこちらで質問させていただきたいです。
googleのカスタム検索に広告が出るのが嫌で、wordpressのサイト内検索にしようとしています。
検索結果をgoogleのカスタム検索の様に
「タイトル」「テキスト抜粋」「アイキャッチ画像」で表示したいのですが、表示の仕方が分かりません。
参考サイトや方法等分かりましたら教えて頂きたいです。
以下、search.phpの中身です。
<?php get_header(); ?> <?php global $wp_query; $total_results = $wp_query->found_posts; $search_query = get_search_query(); ?> <?php global $wpdb; $keyword = get_search_query(); $keyword = '%' . like_escape( $keyword ) . '%'; $post_ids = $wpdb->get_col( $wpdb->prepare( " SELECT DISTINCT post_id FROM {$wpdb->posts} T1, {$wpdb->postmeta} T2 WHERE T1.post_title LIKE '%s' OR T1.post_content LIKE '%s' OR T2.meta_value LIKE '%s' ", $keyword, $keyword, $keyword ) ); $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'post__in' => $post_ids, ); $query = new WP_Query( $args ); ?> <div class="search_result"> <h1 class="result_ttl"><?php echo $search_query; ?>の検索結果<span>(<?php echo $total_results; ?>件)</span></h1> <?php if( $total_results >0 ): if(have_posts()): while(have_posts()): the_post(); ?> <h2 class="search_txt"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p><?php the_excerpt(); ?></p> <?php endwhile; endif; else: ?> <?php echo $search_query; ?> に一致する情報は見つかりませんでした。 <?php endif; ?> </div> <?php get_footer(); ?> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/01/09 02:53