add search filters
This commit is contained in:
@@ -40,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul id="header_icons">
|
<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>
|
<a href="<?=get_site_url()?>/rss/news.xml"><li class="btn_rss"></li></a>
|
||||||
<li class="toggle-nav" id="toggle-nav"></li>
|
<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>
|
<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">
|
<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/">
|
<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/10/vgnki_240x400_october-2.jpg" width="240" height="400" />
|
<img src="https://vetandlife.ru/wp-content/uploads/2022/11/vgnki_240x400_november.jpg" width="240" height="400" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -145,8 +145,8 @@
|
|||||||
|
|
||||||
<?if (LANG_VERSION == 'ru'):?>
|
<?if (LANG_VERSION == 'ru'):?>
|
||||||
<div class="mobile-info">
|
<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">
|
<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/10/vgnki_240x200_october-2.jpg" width="240" height="200" />
|
<img src="https://vetandlife.ru/wp-content/uploads/2022/11/vgnki_240x200_november.jpg" width="240" height="200" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -172,11 +172,37 @@ add_filter( 'single_template', function ( $single_template ) {
|
|||||||
|
|
||||||
#search
|
#search
|
||||||
function my_search_order( $query ) {
|
function my_search_order( $query ) {
|
||||||
|
|
||||||
|
$s = trim($_GET['s']);
|
||||||
|
|
||||||
if ($query->is_search) {
|
if ($query->is_search) {
|
||||||
if (!isset($_GET['search_type']) OR $_GET['search_type'] == 'date'){
|
|
||||||
$query->set( 'order', 'DESC' );
|
if (empty($query)){
|
||||||
$query->set( 'orderby', 'date' );
|
$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;
|
return $query;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<?if (defined('TESTMODE') and TESTMODE == 1):?>
|
<?if (defined('TESTMODE') and TESTMODE == 1):?>
|
||||||
<link rel="stylesheet" href="<?php echo get_template_directory_uri();?>/style-test.css?ver=3">
|
<link rel="stylesheet" href="<?php echo get_template_directory_uri();?>/style-test.css?ver=3">
|
||||||
<?else:?>
|
<?else:?>
|
||||||
<link rel="stylesheet" href="<?php echo get_stylesheet_uri();?>?ver=315">
|
<link rel="stylesheet" href="<?php echo get_stylesheet_uri();?>?ver=325">
|
||||||
<?endif?>
|
<?endif?>
|
||||||
<link href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" rel="stylesheet">
|
<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">-->
|
<!--<link href="<?php echo get_stylesheet_directory_uri()?>/pub/fontawesome.css" rel="stylesheet">-->
|
||||||
|
|||||||
188
search.php
188
search.php
@@ -4,17 +4,127 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
get_header();?>
|
get_header();?>
|
||||||
|
|
||||||
|
<?$s = trim($s);?>
|
||||||
|
|
||||||
<?if (trim($s) !== ''):?>
|
|
||||||
|
|
||||||
<?$params = [
|
<?//if( !empty( $query ) ){
|
||||||
'post_type' => 'post',
|
|
||||||
's' => $s,
|
|
||||||
'post_status' => 'publish',
|
$args = array(
|
||||||
'posts_per_page' => 20
|
'post_type' => 'post',
|
||||||
]?>
|
'post_status' => 'publish',
|
||||||
|
'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">
|
<form action="<?php bloginfo( 'url' ); ?>" method="get">
|
||||||
<input class="search-text" type="text" name="s" placeholder="Найти" value="<?=$s?>"/>
|
<input class="search-text" type="text" name="s" placeholder="Найти" value="<?=$s?>"/>
|
||||||
<input class="search_submit" type="submit" value="Найти"/>
|
<input class="search_submit" type="submit" value="Найти"/>
|
||||||
|
<?if ($s !== ''):?>
|
||||||
<div class="search-result">
|
<div class="search-result">
|
||||||
По запросу «<?php
|
По запросу «<?php
|
||||||
$allsearch = new WP_Query($params);
|
|
||||||
$key = esc_html($s, 1);
|
$key = esc_html($s, 1);
|
||||||
$count = $allsearch->post_count; _e('');
|
$count = $posts->found_posts; _e('');
|
||||||
_e('<span class="search-terms">');
|
_e('<span class="search-terms">');
|
||||||
echo $key; _e('</span>» найдено ');
|
echo $key; _e('</span>» найдено ');
|
||||||
if ($count == 1):
|
if ($count == 1):
|
||||||
@@ -48,29 +158,44 @@ endif;
|
|||||||
//wp_reset_query(); ?>
|
//wp_reset_query(); ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<?endif?>
|
||||||
|
|
||||||
<div id="find_panel">
|
<div id="find_panel">
|
||||||
<select class="search-select" id="search_type" name="search_type">
|
<select class="search-select search-select-type" id="search_type" name="search_type">
|
||||||
<option value="date">По дате</option>
|
<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>
|
<option value="revel" <?if($_GET['search_type'] == 'revel'):?> selected<?endif?>>По релевантности</option>
|
||||||
</select>
|
</select>
|
||||||
<select class="search-select" id="search_date" name="search_date">
|
<select class="search-select search-select-date" id="search_date" name="search_date">
|
||||||
<option value="all" selected>За все время</option>
|
<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>
|
||||||
|
<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>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?//print_r($posts)?>
|
||||||
|
|
||||||
|
|
||||||
|
<?php if ($s !== '' and $posts->have_posts()) :?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?php if(have_posts()) :?>
|
|
||||||
<div class="search-card-box">
|
<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;?>
|
<?php endwhile;?>
|
||||||
</div>
|
</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;?>
|
||||||
|
|
||||||
<?php endif;?>
|
|
||||||
|
|
||||||
<?wp_reset_postdata();?>
|
<?wp_reset_postdata();?>
|
||||||
|
|
||||||
@@ -106,3 +234,19 @@ endif;
|
|||||||
|
|
||||||
|
|
||||||
<?php get_footer(); ?>
|
<?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{
|
.search-select{
|
||||||
width: 155px;
|
|
||||||
border: 0px;
|
border: 0px;
|
||||||
background:none;
|
background:none;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
@@ -288,6 +287,26 @@ a{
|
|||||||
padding-left: 8px;
|
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{
|
.search-text{
|
||||||
width: 60%;
|
width: 60%;
|
||||||
|
|||||||
3
tag.php
3
tag.php
@@ -19,7 +19,8 @@
|
|||||||
<div class="mini-card">
|
<div class="mini-card">
|
||||||
<?if ( has_post_thumbnail() ) :?>
|
<?if ( has_post_thumbnail() ) :?>
|
||||||
<div class="mini-card-img">
|
<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( 'видео' ) ):?>
|
<?if( has_tag( 'видео' ) ):?>
|
||||||
<span class="play-card"></span>
|
<span class="play-card"></span>
|
||||||
<?endif?>
|
<?endif?>
|
||||||
|
|||||||
Reference in New Issue
Block a user