From 1f9e8f76078c744031f97138bd16130c89b17490 Mon Sep 17 00:00:00 2001 From: Dan Head Date: Wed, 12 Dec 2018 20:50:59 +0000 Subject: [PATCH] Search results --- css/index.css | 1 + css/search-result.css | 28 +++++++++++++ theme/functions.php | 8 ++++ theme/icons.php | 3 ++ theme/page.php | 2 +- theme/partials/pagination.php | 18 +++++++-- theme/search.php | 76 +++++++++++++++++++++++++++++++++++ theme/searchform.php | 2 +- 8 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 css/search-result.css create mode 100644 theme/search.php diff --git a/css/index.css b/css/index.css index 32f761e..84a6ae5 100644 --- a/css/index.css +++ b/css/index.css @@ -19,6 +19,7 @@ @import "pagination"; @import "title"; @import "archive"; +@import "search-result"; :root { --color-black: #000; diff --git a/css/search-result.css b/css/search-result.css new file mode 100644 index 0000000..9f55ce3 --- /dev/null +++ b/css/search-result.css @@ -0,0 +1,28 @@ +.search-result { + margin-bottom: var(--space-sm); +} + +.search-result__head, +.search-result__body, +.search-result__title { + margin-bottom: var(--space-xs); +} + +.search-result__metadata { + color: var(--color-grey); + font-size: 12px; +} + +.search-result__icon, +.search-result__text { + display: inline-block; + vertical-align: middle; +} + +.search-result__icon { + height: 16px; +} + +.search-result__text { + margin: 0 15px 0 5px; +} diff --git a/theme/functions.php b/theme/functions.php index d171c45..5aeb900 100644 --- a/theme/functions.php +++ b/theme/functions.php @@ -76,3 +76,11 @@ function windycoys_share_twitter_url() { $link = get_the_permalink(); echo $url . urlencode($title . ': ' . $link . ' by @WindyCOYS'); } + +function windycoys_search_posts_per_page($query) { + if ($query->is_search) { + $query->set( 'posts_per_page', '10' ); + } + return $query; +} +add_filter('pre_get_posts', 'windycoys_search_posts_per_page'); diff --git a/theme/icons.php b/theme/icons.php index ae3364d..16f6b76 100644 --- a/theme/icons.php +++ b/theme/icons.php @@ -23,6 +23,9 @@ + + + diff --git a/theme/page.php b/theme/page.php index ac48fc8..88d6618 100644 --- a/theme/page.php +++ b/theme/page.php @@ -22,7 +22,7 @@

Sorry, there is no article to display

- Go back home + Go back home
diff --git a/theme/partials/pagination.php b/theme/partials/pagination.php index 720c4a3..f523a45 100644 --- a/theme/partials/pagination.php +++ b/theme/partials/pagination.php @@ -10,14 +10,26 @@ $links = paginate_links(array( )); function get_previous_url($base_url, $page) { - return $base_url . ($page - 1); + $qs = $_SERVER['QUERY_STRING']; + $url = $base_url . ($page - 1); + if ($qs) { + $url .= '/?' . $qs; + } + return $url; } function get_next_url($base_url, $page) { + $qs = $_SERVER['QUERY_STRING']; + $url = $base_url; if ($page === 0) { - return $base_url . '2'; + $url .= '2'; + } else { + $url .= ($page + 1); } - return $base_url . ($page + 1); + if ($qs) { + $url .= '/?' . $qs; + } + return $url; } function format_link($link) { if (strpos($link, 'page-numbers dots')) { diff --git a/theme/search.php b/theme/search.php new file mode 100644 index 0000000..bd65ac7 --- /dev/null +++ b/theme/search.php @@ -0,0 +1,76 @@ + +
+ +
+
+

+ found_posts.' results matching "' . $query . '" found.'; + ?> +

+
    + + + +
  1. +
    +
    +
    + + + +
    +
    +
    + +
    +
    + +
    +
    +
  2. + +
+
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ + diff --git a/theme/searchform.php b/theme/searchform.php index e4a498b..9839f28 100644 --- a/theme/searchform.php +++ b/theme/searchform.php @@ -1,4 +1,4 @@ -