add search filters
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
</div>
|
||||
|
||||
<ul id="header_icons">
|
||||
<a href="<?=get_site_url()?>?s=ВиЖ"><li class="btn_search"></li></a>
|
||||
<a href="<?=get_site_url()?>?s"><li class="btn_search"></li></a>
|
||||
<a href="<?=get_site_url()?>/rss/news.xml"><li class="btn_rss"></li></a>
|
||||
<li class="toggle-nav" id="toggle-nav"></li>
|
||||
<a href="<?=get_site_url().vij_lang('btn_lan_link', LANG_VERSION)?>"><li class="btn_lan"><nobr><?=vij_lang('btn_lan', LANG_VERSION)?></nobr></li></a>
|
||||
|
||||
8
blocks/search-paginator.php
Normal file
8
blocks/search-paginator.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php if ( $wp_query->max_num_pages > 1 ) : ?><div class="pagination-wrapper"><?php the_posts_pagination( array(
|
||||
'prev_text' => __( '< '.vij_lang('prev', LANG_VERSION), 'quidus' ),
|
||||
'next_text' => __( vij_lang('next', LANG_VERSION).' >', 'quidus' ),
|
||||
'end_size' => 2,
|
||||
'mid_size' => 3,
|
||||
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'quidus' ) . ' </span>',
|
||||
) );
|
||||
?></div><?php endif;?>
|
||||
@@ -79,8 +79,8 @@
|
||||
|
||||
|
||||
<div class="right-info">
|
||||
<a href=" https://vetandlife.ru/parthers/fgbu-vgnki-okazyvaet-uslugi-po-razrabotke-meropriyatij-po-sanacii-zhivotnovodcheskih-i-pticevodcheskih-hozyajstv-ot-bakterialnyh-infekcij-posredstvom-provedeniya-laboratorno-diagnosticheskih-issledova/">
|
||||
<img src="https://vetandlife.ru/wp-content/uploads/2022/10/vgnki_240x400_october-2.jpg" width="240" height="400" />
|
||||
<a href="https://vetandlife.ru/parthers/fgbu-vgnki-provodit-obuchajushhie-meropriyatiya-dlya-razlichnyh-kategorij-specialistov-agropromyshlennogo-kompleksa/">
|
||||
<img src="https://vetandlife.ru/wp-content/uploads/2022/11/vgnki_240x400_november.jpg" width="240" height="400" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -145,8 +145,8 @@
|
||||
|
||||
<?if (LANG_VERSION == 'ru'):?>
|
||||
<div class="mobile-info">
|
||||
<a href="https://vetandlife.ru/parthers/fgbu-vgnki-okazyvaet-uslugi-po-razrabotke-meropriyatij-po-sanacii-zhivotnovodcheskih-i-pticevodcheskih-hozyajstv-ot-bakterialnyh-infekcij-posredstvom-provedeniya-laboratorno-diagnosticheskih-issledova/" target="_blank">
|
||||
<img src="https://vetandlife.ru/wp-content/uploads/2022/10/vgnki_240x200_october-2.jpg" width="240" height="200" />
|
||||
<a href="https://vetandlife.ru/parthers/fgbu-vgnki-provodit-obuchajushhie-meropriyatiya-dlya-razlichnyh-kategorij-specialistov-agropromyshlennogo-kompleksa/" target="_blank">
|
||||
<img src="https://vetandlife.ru/wp-content/uploads/2022/11/vgnki_240x200_november.jpg" width="240" height="200" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -172,11 +172,37 @@ add_filter( 'single_template', function ( $single_template ) {
|
||||
|
||||
#search
|
||||
function my_search_order( $query ) {
|
||||
|
||||
$s = trim($_GET['s']);
|
||||
|
||||
if ($query->is_search) {
|
||||
if (!isset($_GET['search_type']) OR $_GET['search_type'] == 'date'){
|
||||
$query->set( 'order', 'DESC' );
|
||||
$query->set( 'orderby', 'date' );
|
||||
|
||||
if (empty($query)){
|
||||
$query .=" AND 0=1 ";
|
||||
return $query;
|
||||
}
|
||||
|
||||
if(strpos($s, "#") !== false) {
|
||||
|
||||
//$terms = explode('#', $s);
|
||||
$terms = substr($s, 1);
|
||||
|
||||
$query->set('tax_query', [
|
||||
'relation' => 'OR',
|
||||
[
|
||||
'taxonomy' => 'post_tag',
|
||||
'field' => 'name',
|
||||
'terms' => $terms
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
// if (!isset($_GET['search_type']) OR $_GET['search_type'] == 'date'){
|
||||
// $query->set( 'order', 'DESC' );
|
||||
// $query->set( 'orderby', 'date' );
|
||||
// }
|
||||
|
||||
};
|
||||
return $query;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<?if (defined('TESTMODE') and TESTMODE == 1):?>
|
||||
<link rel="stylesheet" href="<?php echo get_template_directory_uri();?>/style-test.css?ver=3">
|
||||
<?else:?>
|
||||
<link rel="stylesheet" href="<?php echo get_stylesheet_uri();?>?ver=315">
|
||||
<link rel="stylesheet" href="<?php echo get_stylesheet_uri();?>?ver=325">
|
||||
<?endif?>
|
||||
<link href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" rel="stylesheet">
|
||||
<!--<link href="<?php echo get_stylesheet_directory_uri()?>/pub/fontawesome.css" rel="stylesheet">-->
|
||||
|
||||
184
search.php
184
search.php
@@ -4,17 +4,127 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
get_header();?>
|
||||
|
||||
<?$s = trim($s);?>
|
||||
|
||||
<?if (trim($s) !== ''):?>
|
||||
|
||||
<?$params = [
|
||||
<?//if( !empty( $query ) ){
|
||||
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
's' => $s,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 20
|
||||
]?>
|
||||
'posts_per_page' => 20,
|
||||
'paged' => get_query_var('paged') ?: 1
|
||||
);
|
||||
|
||||
if ( $_GET['search_type'] == 'date_down'){
|
||||
|
||||
$args['order'] = 'DESC';
|
||||
$args['orderby'] = 'date';
|
||||
|
||||
}
|
||||
else if($_GET['search_type'] == 'date_up') {
|
||||
|
||||
$args['order'] = 'ASC';
|
||||
$args['orderby'] = 'date';
|
||||
|
||||
}
|
||||
|
||||
$findtag = strpos($s, "#");
|
||||
|
||||
if( $findtag !== false OR $_GET['search_select'] == 'tag') {
|
||||
|
||||
$active_tag = True;
|
||||
|
||||
if ($findtag == false) {
|
||||
$terms = $s;
|
||||
}
|
||||
else {
|
||||
$terms = substr($s, 1);
|
||||
}
|
||||
|
||||
$args['tax_query'] = [
|
||||
'relation' => 'OR',
|
||||
[
|
||||
'taxonomy' => 'post_tag',
|
||||
'field' => 'name',
|
||||
'terms' => $terms
|
||||
]
|
||||
];
|
||||
}
|
||||
else {
|
||||
$active_tag = false;
|
||||
$args['s'] = $s;
|
||||
}
|
||||
|
||||
|
||||
if($_GET['search_date'] == 'week') {
|
||||
|
||||
$args['date_query'] = [
|
||||
[
|
||||
'after' => '1 week ago'
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
else if ($_GET['search_date'] == 'month'){
|
||||
|
||||
$args['date_query'] = [
|
||||
[
|
||||
'after' => '1 month ago'
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
else if ($_GET['search_date'] == 'year'){
|
||||
|
||||
$args['date_query'] = [
|
||||
[
|
||||
'after' => '1 year ago'
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
else if ($_GET['search_date'] == 'range'){
|
||||
|
||||
if (isset($_GET['search-start-date']) and $_GET['search-start-date'] !== ''){
|
||||
$date1 = explode('-', $_GET['search-start-date']);
|
||||
}
|
||||
|
||||
if (isset($_GET['search-end-date']) and $_GET['search-end-date'] !== ''){
|
||||
$date2 = explode('-', $_GET['search-end-date']);
|
||||
}
|
||||
|
||||
|
||||
$args['date_query'] = [
|
||||
[
|
||||
array(
|
||||
'after' => array(
|
||||
'year' => $date1[0],
|
||||
'month' => $date1[1],
|
||||
'day' => $date1[13],
|
||||
),
|
||||
'before' => array( // до этой даты
|
||||
'year' => $date2[0],
|
||||
'month' => $date2[1],
|
||||
'day' => $date2[2],
|
||||
),
|
||||
)
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
$posts = new WP_Query($args);
|
||||
|
||||
|
||||
|
||||
//}?>
|
||||
|
||||
|
||||
|
||||
@@ -28,12 +138,12 @@ get_header();?>
|
||||
<form action="<?php bloginfo( 'url' ); ?>" method="get">
|
||||
<input class="search-text" type="text" name="s" placeholder="Найти" value="<?=$s?>"/>
|
||||
<input class="search_submit" type="submit" value="Найти"/>
|
||||
|
||||
<?if ($s !== ''):?>
|
||||
<div class="search-result">
|
||||
По запросу «<?php
|
||||
$allsearch = new WP_Query($params);
|
||||
|
||||
$key = esc_html($s, 1);
|
||||
$count = $allsearch->post_count; _e('');
|
||||
$count = $posts->found_posts; _e('');
|
||||
_e('<span class="search-terms">');
|
||||
echo $key; _e('</span>» найдено ');
|
||||
if ($count == 1):
|
||||
@@ -48,29 +158,44 @@ endif;
|
||||
//wp_reset_query(); ?>
|
||||
|
||||
</div>
|
||||
<?endif?>
|
||||
|
||||
<div id="find_panel">
|
||||
<select class="search-select" id="search_type" name="search_type">
|
||||
<option value="date">По дате</option>
|
||||
<select class="search-select search-select-type" id="search_type" name="search_type">
|
||||
<option value="date_down">По дате <span class="date_arrow">↓</span></option>
|
||||
<option value="date_up" <?if($_GET['search_type'] == 'date_up'):?> selected<?endif?>>По дате <span class="date_arrow">↑</span></option>
|
||||
<option value="revel" <?if($_GET['search_type'] == 'revel'):?> selected<?endif?>>По релевантности</option>
|
||||
</select>
|
||||
<select class="search-select" id="search_date" name="search_date">
|
||||
<option value="all" selected>За все время</option>
|
||||
<select class="search-select search-select-date" id="search_date" name="search_date">
|
||||
<option value="all">За все время</option>
|
||||
<option value="week" <?if($_GET['search_date'] == 'week'):?> selected<?endif?>>За неделю</option>
|
||||
<option value="month" <?if($_GET['search_date'] == 'month'):?> selected<?endif?>>За месяц</option>
|
||||
<option value="year" <?if($_GET['search_date'] == 'year'):?> selected<?endif?>>За год</option>
|
||||
<option value="range" <?if($_GET['search_date'] == 'range'):?> selected<?endif?>>За период</option>
|
||||
</select>
|
||||
<select class="search-select search-select-tags" id="search_select" name="search_select">
|
||||
<option value="all">Все</option>
|
||||
<option value="tag"<?if ($active_tag):?> selected<?endif?>>Теги</option>
|
||||
</select>
|
||||
|
||||
<div id="search-calendar" style="visibility: <?if($_GET['search_date'] == 'range'):?>visible<?else:?>hidden<?endif?>;">
|
||||
<input id="search-start-date" name="search-start-date" type="date" value = "<?if (isset($_GET['search-start-date']) and $_GET['search-start-date'] !== '' ):?><?=$_GET['search-start-date']?><?else:?><?=date('Y-m-d')?><?endif?>">
|
||||
-
|
||||
<input id="search-end-date" name="search-end-date" value = "<?if (isset($_GET['search-end-date']) and $_GET['search-end-date'] !== ''):?><?=$_GET['search-end-date']?><?else:?><?=date('Y-m-d')?><?endif?>" type="date">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?//print_r($posts)?>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?php if(have_posts()) :?>
|
||||
<?php if ($s !== '' and $posts->have_posts()) :?>
|
||||
<div class="search-card-box">
|
||||
|
||||
<?php while(have_posts()) : the_post();?>
|
||||
<?php while($posts->have_posts()) : $posts->the_post();?>
|
||||
|
||||
|
||||
|
||||
@@ -92,12 +217,15 @@ endif;
|
||||
<?php endwhile;?>
|
||||
</div>
|
||||
|
||||
<?get_template_part( '/blocks/paginator');?>
|
||||
|
||||
|
||||
<?
|
||||
$GLOBALS['wp_query']->max_num_pages = $posts->max_num_pages;
|
||||
get_template_part( '/blocks/paginator');?>
|
||||
|
||||
|
||||
<?php endif;?>
|
||||
|
||||
<?php endif;?>
|
||||
|
||||
<?wp_reset_postdata();?>
|
||||
|
||||
@@ -106,3 +234,19 @@ endif;
|
||||
|
||||
|
||||
<?php get_footer(); ?>
|
||||
|
||||
<script>
|
||||
|
||||
var search_date_select = document.getElementById('search_date');
|
||||
var data_range_panel = document.getElementById('search-calendar');
|
||||
|
||||
search_date_select.addEventListener('change', function() {
|
||||
|
||||
if (search_date_select.selectedIndex == 4) {
|
||||
data_range_panel.style.visibility = "visible";
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
</script>
|
||||
21
style.css
21
style.css
@@ -280,7 +280,6 @@ a{
|
||||
}
|
||||
|
||||
.search-select{
|
||||
width: 155px;
|
||||
border: 0px;
|
||||
background:none;
|
||||
font-size: 14px;
|
||||
@@ -288,6 +287,26 @@ a{
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
#search-calendar{
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.search-select-type{
|
||||
width: 155px;
|
||||
}
|
||||
|
||||
.search-select-tags{
|
||||
width: 60px;
|
||||
}
|
||||
|
||||
.search-select-date{
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.date_arrow{
|
||||
font-size: 10px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.search-text{
|
||||
width: 60%;
|
||||
|
||||
3
tag.php
3
tag.php
@@ -19,7 +19,8 @@
|
||||
<div class="mini-card">
|
||||
<?if ( has_post_thumbnail() ) :?>
|
||||
<div class="mini-card-img">
|
||||
<a href="<?the_permalink();?>"><img class="mini-card-img" src="<?php echo get_the_post_thumbnail_url(null, 'large'); ?>" alt="<?the_title();?>"></a>
|
||||
<?$imgurl = IMGSERVER.'news/512x340/'.str_replace('https://vetandlife.ru/wp-content/uploads/', '', get_the_post_thumbnail_url(null, 'full'))?>
|
||||
<a href="<?the_permalink();?>"><img class="mini-card-img" src="<?php echo $imgurl; ?>" alt="<?the_title();?>"></a>
|
||||
<?if( has_tag( 'видео' ) ):?>
|
||||
<span class="play-card"></span>
|
||||
<?endif?>
|
||||
|
||||
Reference in New Issue
Block a user