Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created January 10, 2014 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramseyp/8345807 to your computer and use it in GitHub Desktop.
Save ramseyp/8345807 to your computer and use it in GitHub Desktop.
Search within a WordPress category archive ( Genesis )
<?php
/**
*
* first function gets URL of the current page, which is used in the search as the action parameter.
* second function loads a search box above the content of a Genesis category archive.
* the category name ( slug ) is passed through a hidden input as a search query parameter.
*
**/
function current_page_url() {
$pageURL = 'http';
if( isset($_SERVER["HTTPS"]) ) {
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
add_action( 'genesis_before_content','atx_cat_search' );
function atx_cat_search() {
global $wp_query;
$my_cat = $wp_query->query_vars['category_name'];
if ( is_category() ) :
echo '
<form method="get" class="search-form" action="'. current_page_url() .'" role="search">
<input type="search" name="s" />
<input type="hidden" name="category_name" id="category_name" value="'. $my_cat .'" />
<input type="submit" value="'. __( 'Search','atx' ) .'" />
</form>
';
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment