Wordpress 搜索栏只输出帖子标题 [英] Wordpress search bar outputting only posts titles
问题描述
我想用 PHP 创建一个 Wordpress 搜索栏,只显示在我网站的一个页面中(我正在开发一个我制作的新主题).因此,搜索栏应仅输出与搜索关键字相关的帖子的永久链接(标题).
我现在遇到的问题是搜索输出显示 lorem ipsum 文本和侧边栏.无论我搜索什么关键字,都会显示相同的输出.(见截图).
非常感谢您的帮助!
searchform.php
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"><标签><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' ) ?>"/>标签><input type="submit" class="search-submit" value="<?php echo esc_attr_x('搜索', '提交按钮') ?>"/>
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/* 翻译器:%s:搜索查询.*/printf( esc_html__( 'Search Results for: %s', 'materialpress' ), '' . get_search_query() . '' );?></h1></header><!-- .page-header --><?phpwhile ( have_posts() ) : the_post();/* 确保模板是你的 content.php */get_template_part('内容');终了;the_posts_navigation();别的 :/* 显示没有找到内容的页面 */echo '未找到帖子';万一;?></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="容器"><div id="content_post"><div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><?php the_content();?>
<?php endwhile;?><?php endif;?>
content-search.php
<?php get_header();?><?php if (have_posts()): ?><div class="容器"><?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>