Skip to content

Refactor search page to match category page. #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions themes/api.jqueryui.com/search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
get_header();
get_template_part( 'search', 'api' );
get_footer();
?>
18 changes: 6 additions & 12 deletions themes/jquery/category-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@
?>
</header>

<?php //twentyeleven_content_nav( 'nav-above' ); ?>

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>

<?php
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', 'api' );
?>

<?php endwhile; ?>
endwhile;
?>

<?php twentyeleven_content_nav( 'nav-below' ); ?>

Expand All @@ -50,8 +45,7 @@
<?php endif; ?>

</div><!-- .inner -->
<?php if($sidebar): ?>
<?php get_sidebar( 'api' ); ?>
<?php endif; ?>

<?php if ( $sidebar ) : get_sidebar( 'api' ); endif; ?>

</section><!-- #body -->
7 changes: 7 additions & 0 deletions themes/jquery/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ a:hover {
}

.home .post,
.search .post,
.category .post {
padding: 10px 10px 10px 20px;
margin: 20px 0;
Expand All @@ -815,18 +816,21 @@ a:hover {
}

.home .post .entry-title,
.search .post .entry-title,
.category .post .entry-title {
font-size: 140%;
margin-bottom: .2em;
}

.home .post header .entry-meta,
.search .post header .entry-meta,
.category .post header .entry-meta {
float: right;
margin: 0;
}

.home .post header .entry-meta .category,
.search .post header .entry-meta .category,
.category .post header .entry-meta .category {
padding: 3px;
margin-left: 5px;
Expand All @@ -837,17 +841,20 @@ a:hover {
}

.home .post header .entry-meta .category:hover,
.search .post header .entry-meta .category:hover,
.category .post header .entry-meta .category:hover {
background-color: #cccccc;
}

.home .post header .entry-meta .category a,
.search .post header .entry-meta .category a,
.category .post header .entry-meta .category a {
color: #888888;
text-decoration: none;
}

.home .post .category-divider,
.search .post .category-divider,
.category .post .category-divider {
display: none;
}
Expand Down
95 changes: 35 additions & 60 deletions themes/jquery/search-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,51 @@
* The template for displaying Search Results pages.
*/
?>
<?php global $sidebar; ?>

<!-- body -->
<?php global $sidebar; ?>
<div id="body" class="clearfix <?php echo $sidebar; ?>">
<div class="inner" role="main">
<?php
$searchquery = get_search_query();
$searchquery = preg_replace('/\$/', 'jQuery', $searchquery);
$featuredlist = array();
$entrylist = array();
<section id="body" class="clearfix <?php echo $sidebar; ?>">
<div class="inner" role="main">

?>
<?php if ( have_posts() ) : ?>
<?php
$searchquery = get_search_query();
$searchquery = preg_replace('/\$/', 'jQuery', $searchquery);
$featuredlist = array();
$entrylist = array();
?>

<?php // twentyeleven_content_nav( 'nav-above' ); ?>
<?php if ( have_posts() ) : ?>

<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
</header>
<header class="page-header">
<h1 class="page-title"><?php
printf( __( 'Search Results for: %s', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' );
?></h1>
<hr class="dots">
</header>

<?php
while ( have_posts() ) :
the_post();
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', 'api' );
endwhile;
?>

$tentry = '<article id="post-' . $post->ID . '" class="' . implode( ' ', get_post_class() ) . '">';
$tentry .= '<header class="entry-header">';
$tentry .= '<h1 class="entry-title">';
$tentry .= '<a href="' . get_permalink() . '" rel="bookmark">';
$tentry .= $post->post_title;
$tentry .= '</a>';
$tentry .= '</h1>';
$tentry .= '</header>';
$tentry .= '<div class="entry-summary">';
$tentry .= $post->post_excerpt;
$tentry .= '</div>';
$tentry .= '</article>';
<?php twentyeleven_content_nav( 'nav-below' ); ?>

if ( preg_match('@' . $searchquery . '@i', $post->post_name) ) :
$featuredlist[$post->post_name] = $tentry;
else :
$entrylist[$post->post_name] = $tentry;
endif;
<?php else : ?>

endwhile;
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->

echo implode("\n", $featuredlist);
ksort($entrylist);
echo implode("\n", $entrylist);
<div class="entry-content">
<p><?php _e( 'Apologies, but nothing matched your search criteria.', 'twentyeleven' ); ?></p>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bubbling entries with names that contain the search term to the top. The new code just calls out to the content template, so we lose the sorting. @nacin is there a way to weight the sort results so that we don't need to do this?

</div><!-- .entry-content -->
</article><!-- #post-0 -->

?>
<?php endif; ?>

<?php else : ?>
</div><!-- .inner -->

<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content">
<p><?php _e( 'Apologies, but nothing matched your search criteria.', 'twentyeleven' ); ?></p>
</div><!-- .entry-content -->
</article><!-- #post-0 -->

<?php endif; ?>

</div><!-- .inner -->

<?php if($sidebar): ?>
<?php get_sidebar( 'api' ); ?>
<?php endif; ?>

</div><!-- #body -->
<?php if ( $sidebar ) : get_sidebar( 'api' ); endif; ?>

</section><!-- #body -->