私は自分のサイトの1ページに表示されるWordpress検索バーを作成したいと思います(私が作った新しいテーマに取り組んでいます)。結果として、検索バーは、検索キーワードに関連する自分の投稿のパーマリンク(タイトル)のみを出力するはずです。
私が今問題になっているのは、検索出力にlorem ipsumテキストとサイドバーが表示されていることです。どんなキーワードを検索しても、同じ出力が表示されます。 (スクリーンショットを参照)。
ご協力いただきありがとうございます。
searchform.phpWordpressの検索バーの投稿のみを出力する
<form role="search" method="get" class="search-form" action="<?php echo home_url('/'); ?>">
<label>
<span class="screen-reader-text"><?php echo _x('Search for:', 'label') ?></span>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x('search', 'placeholder') ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x('Search for:', 'label') ?>" />
</label>
<input type="submit" class="search-submit" value="<?php echo esc_attr_x('Search', 'submit button') ?>" />
</form>
search.php
<?php get_header(); ?>
<section id="primary" class="content-area">
<main id="main" class="site-main">
<?php if (have_posts()) : ?>
<header class="page-header">
<h1 class="page-title"><?php
/* translators: %s: search query. */
printf(esc_html__('Search Results for: %s', 'materialpress'), '<span>' . get_search_query() . '</span>');
?></h1>
</header><!-- .page-header -->
<?php
while (have_posts()) : the_post();
/* Make sure the template is your content.php */
get_template_part('content');
endwhile;
the_posts_navigation();
else :
/* Show no content found page */
echo 'Not posts found';
endif; ?>
</main><!-- #main -->
</section><!-- #primary -->
<?php get_sidebar(); get_footer();
mypage.php
<?php get_header(); ?>
<?php get_search_form(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="container">
<div id="content_post">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php the_content(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
コンテンツsearch.php
<?php get_header(); ?>
<?php if (have_posts()): ?>
<div class="container">
<?php while(have_posts()): the_post(); ?>
<div class="row-posts-container">
<div class="row-posts">
<div class="posts col-lg-12 hidden-sm col-md-12 hidden-xs">
<a href="<?php the_permalink(); ?>"><?php $first = str_replace(' | ', '<br />', get_the_title()); echo str_replace('REPLACE_ME', '<i>REPLACE_ME</i>', $first);?></a>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
![enter image description here](https://i.stack.imgur.com/eFzag.png)
であり、あなたが持っている問題は何であるため、これを実行する必要がありますか?あなたは私たちにコードを与えましたが、問題が何であるか、それを修正するためにあなたがすでに行ったことは教えてくれませんでした。 [良い質問をするにはどうすればいいですか](https://stackoverflow.com/help/how-to-ask)をご覧ください。 – FluffyKitten
私はあなたを助けることができるようにcontent.phpファイルの中にコードを貼り付けることができます。 –
@RajendranNadarあなたはcontent.phpファイルの名前をつけていますか?それはmypage.phpですか?そのファイルにすべてのコードを貼り付ける必要がありますか? – Lolo