I am working on a custom theme. My issue is that when I use the search form it will show the search results as it is suppose to but when I use the pagination on the page it just takes me back to my home page.
I have wordpress installed in a wordpress sub-directory that is accessible from /blog. I have a static front page (front-page.php) and blog page (home.php) and the site works fine for the most part. I am having a few issues with post per page on the initial blog page but I already have a question for that posted on this site.
This issue is that the search page works on the initial search submission but the pagination does not maintain the /search/%s format.
EDIT
I was able to get it to work by changing the form method="post"
to method="get"
but this appends the ?s=%s I would like to keep this with clean URLs if possible so I am leaving this open still until I can figure this out.
I have provided my code below:
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( '« Older posts'); ?></span>
<?php
}
if (get_previous_posts_link()) { ?>
<span class="nav-button newer-posts"><?php previous_posts_link( 'Newer posts »' ); ?></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(); ?> | <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>
<!-- <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; ?>
customsearch.php in content :
http://pastebin.com/mxVPphXa
customsearch.php should be here: yoursite.com/dir/customsearch.php