我是Wordpress的新手,我一直在用遐想大师建立一个主题,但唯一的问题是搜索页面。所有其他页面,类别,存档等都在工作。
我用它来搜索我的header.php:
<form method="post" action="<?php echo home_url('/'); ?>" class="search-form" role="search">
<div class="small-9 columns no-pad">
<input type="text" class="search-input" name="s" placeholder="Search" value="" />
</div>
<div class="small-3 columns no-pad">
<input class="btn-submit postfix search-input" type="submit" value=""/>
</div>
这将显示主页上的搜索结果。如果我在搜索栏中输入“ok”,我会举例:www.homepage.com,它应该在www.homepage.com/?s=ok上。它在主页上的问题,分页将带您到家庭博客供稿的第2页,而不是www.homepage.com/page/2/,当它应该是ilke这个www.homepage.com/page/ 2 /?S =测试
当我在浏览器中手动输入此网址时:www.homepage.com/page/2/?s = test分页正在运行。我的问题是分页,我想知道为什么帖子显示在主页上(我认为这是问题)
这是我的search.php代码:
Starts with <?php get_header(); ?> and ends with <?php get_footer(); ?>
这是分页之间的循环:
<h2><?php _e('Search Results for', 'reverie'); ?> "<?php echo get_search_query(); ?>"</h2>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="row pad-row">
<div class="large-11 columns bor-bottom">
<a class="fade" href="<?php the_permalink(); ?>"><p class="feed-title"><?php the_title(); ?></p></a>
<p class="feed-info">By <span class="feed-author"><?php the_author(); ?> </span> • <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?> •
<?php
foreach((g_the_category()) as $category) {
if ($category->cat_name != 'featured') {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
}
}
?>
• <span class="feed-cmt"><?php comments_number( '0 Comments', '1 Comments', '% Comments' ); ?>. </span></p>
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; // end have_posts() check ?>
<!-- Start Pagination -->
<div class="row pad-row">
<div class="large-11 columns pagination-centered large-centered panel-page">
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( function_exists('reverie_pagination') ) { reverie_pagination(); } else if ( is_paged() ) { ?>
<nav id="post-nav">
<div class="post-previous"><?php next_posts_link( __( '← Older posts', 'reverie' ) ); ?></div>
<div class="post-next"><?php previous_posts_link( __( 'Newer posts →', 'reverie' ) ); ?></div>
</nav>
<?php } ?>
</div>
</div>
答案 0 :(得分:1)
不要直接放置搜索表单。 WP具有获取名为get_search_form()
的搜索表单的功能。此功能打印wp基本搜索表单,但您仍然可以自定义它。要进行自定义,您可以使用名为get_search_form的过滤器。
function custom_search_form( $form ) {
$form = '<form method="get" action="' . home_url('/') . '" class="search-form" role="search">
<div class="small-9 columns no-pad">
<input type="text" class="search-input" name="s" id="s" placeholder="Search" value="' . get_search_query() . '" />
</div>
<div class="small-3 columns no-pad">
<input class="btn-submit postfix search-input" id="searchsubmit" type="submit" value="'. esc_attr__( 'Search' ) .'"/>
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'custom_search_form' );
并将其添加到 functions.php