搜索页面分页不起作用

时间:2012-09-06 作者:Jeremy

我正在制作一个自定义主题。我的问题是,当我使用搜索表单时,它会按预期显示搜索结果,但当我在页面上使用分页时,它只会将我带回主页。

我在wordpress子目录中安装了wordpress,可以从/blog访问。我有一个静态首页(front page.php)和博客页(home.php),该网站在大部分情况下运行良好。在最初的博客页面上,我对每页的帖子都有一些问题,但我已经对此网站上发布的帖子提出了一个问题。

这个问题是搜索页面在初始搜索提交时起作用,但分页没有保持/search/%s格式。

EDIT我可以通过改变表格来让它工作method="post"method="get" 但这是附加的?s=%s如果可能的话,我想用干净的URL保持这个,所以我会一直保持这个打开状态,直到我能解决这个问题。

我已提供以下代码:

search.php

<?php
/**
* The template for displaying Search Results pages.
*
* @package WordPress
* @subpackage EHRScopev2
*/
?>

<?php get_header(); ?>      

<div id="main">
    <div id="content">
        <h2 class="home-label"><?php printf(__(\'Search Results for: %s\', \'ehrscope\'), \'<strong><em>\' . get_search_query() . \'</em></strong>\'); ?></h2>
        <?php
        /* Run the loop to output the page.
        * If you want to overload this in a child theme then include a file
        * called loop-page.php and that will be used instead.
        */
        get_template_part(\'loop\', \'single\');
        ?>
        <div class="page-nav">
            <?php if (get_next_posts_link()) { ?>
            <span class="nav-button older-posts"><?php next_posts_link( \'&laquo; Older posts\'); ?></span>
            <?php 
            }
            if (get_previous_posts_link()) { ?>
            <span class="nav-button newer-posts"><?php previous_posts_link( \'Newer posts &raquo;\' ); ?></span>
            <?php } ?>
        </div>       
    </div>
    <?php get_sidebar(); ?>
</div>

<?php get_footer(); ?>

searchform.php

<form method="post" action="<?php echo home_url(\'/\'); ?>" class="search-form" role="search">
    <fieldset>
        <input type="text" name="s" value="<?php echo (is_search()) ? get_search_query() : __(\'Search...\', \'ehrscope\'); ?>" />
        <input class="btn-submit" type="submit" value="<?php _e(\'Submit\', \'ehrscope\'); ?>"/>
    </fieldset>
</form>

loop-single.php

<?php
/**
* The loop that displays a single post.
*
* The loop displays the posts and the post content. See
* http://codex.wordpress.org/The_Loop to understand it and
* http://codex.wordpress.org/Template_Tags to understand
* the tags used in it.
*
* This can be overridden in child themes with loop-single.php.
*
* @package WordPress
* @subpackage EHRScopev2
*/
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="box">
            <div class="box-holder">
                <div class="box-frame">
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        <em class="meta"><?php ehrscope_posted_on(); ?>&nbsp;|&nbsp;<span class="total-comments"><?php comments_popup_link(); ?></span></em>
                        <?php
                        if (!is_single() && has_excerpt()):
                            the_excerpt();
                        else:
                            the_content(__(\'Continue reading\', \'ehrscope\') . \': <em>\' . the_title(\'\', \'\', false) . \'</em>\');
                        endif;
                        ?>
                        <div class="clear"></div>
                        <?php
                        if (is_single()):
                            ehrscope_wp_link_pages();
                            $tags = wp_get_post_tags($post->ID);
                            ?>
                            <p class="entry-meta"><?php ehrscope_show_tags(); ?></p>
                            <?php if ($tags): ?>
                                <a href="javascript:void(0);" id="toggle-related-posts" class="button"><?php _e(\'Show Related Posts\', \'ehrscope\'); ?></a>
                                <?php
                            endif;
                        endif;
                        ?>
                    </div>
                </div>
            </div>
        </div>

        <?php if (is_single()): ?>
            <div class="box" id="related-posts-cage">
                <div class="box-holder">
                    <div class="box-frame">
                        <div>
                            <?php if (is_single()): ?>
                                <?php
                                if ($tags):
                                    $tag_ids = array();
                                    foreach ($tags as $individual_tag) {
                                        $tag_ids[] = $individual_tag->term_id;
                                    }
                                    $args = array(
                                        \'tag__in\' => $tag_ids,
                                        \'post__not_in\' => array($post->ID),
                                        \'posts_per_page\' => 10, // Number of related posts to display.
                                        \'caller_get_posts\' => 1
                                    );
                                    $my_query = new WP_Query($args);
                                    if ($my_query->have_posts()):
                                        ?>
                                        <h3><?php _e(\'Related Posts\', \'ehrscope\'); ?></h3>
                                        <ul>
                                            <?php
                                            while ($my_query->have_posts()) : $my_query->the_post();
                                                ?>
                                                <li>
                                                    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                                                    &nbsp;
                            <!--                                                <span class="related-posts-date"><?php the_time(\'F jS, Y\'); ?></span>-->
                                                </li>
                                                    <?php
                                            endwhile;
                                            ?>
                                        </ul>
                                        <?php
                                    endif;
                                endif;
                            endif;
                            ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        endif;
        comments_template(\'\', true);
    endwhile;
else:
    ?>
    <div class="box">
        <div class="box-holder">
            <div class="box-frame">
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <h2><?php _e(\'No Results\', \'ehrscope\'); ?></h2>
                    <p><?php _e(\'Sorry, no posts matched your criteria.\', \'ehrscope\'); ?></p>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>

1 个回复
SO网友:cudjex

   <form method="post" action="<?php bloginfo(\'url\'); ?>/customsearch.php" class="search-form" role="search"> ... </form>
自定义搜索。php内容:

http://pastebin.com/mxVPphXa

自定义搜索。php应该在这里:yoursite。com/dir/customsearch。php

结束