去掉文章列表页的使用发布时间筛选功能

This commit is contained in:
2026-03-07 20:22:47 +08:00
parent 9be0018a1e
commit 589e221f2d
2 changed files with 92 additions and 154 deletions
+16 -68
View File
@@ -10,8 +10,6 @@ $is_itstudio_content_page = $is_itstudio_news_page || $is_itstudio_notice_page;
<?php if ($is_itstudio_content_page) : ?> <?php if ($is_itstudio_content_page) : ?>
<?php <?php
$keyword = isset($_GET['q']) ? sanitize_text_field(wp_unslash($_GET['q'])) : ''; $keyword = isset($_GET['q']) ? sanitize_text_field(wp_unslash($_GET['q'])) : '';
$date_from = isset($_GET['date_from']) ? sanitize_text_field(wp_unslash($_GET['date_from'])) : '';
$date_to = isset($_GET['date_to']) ? sanitize_text_field(wp_unslash($_GET['date_to'])) : '';
$tag_slug = isset($_GET['tag']) ? sanitize_title(wp_unslash($_GET['tag'])) : ''; $tag_slug = isset($_GET['tag']) ? sanitize_title(wp_unslash($_GET['tag'])) : '';
$paged = max(1, (int) get_query_var('paged'), (int) get_query_var('page')); $paged = max(1, (int) get_query_var('paged'), (int) get_query_var('page'));
$active_post_type = $is_itstudio_news_page ? 'news' : 'announcement'; $active_post_type = $is_itstudio_news_page ? 'news' : 'announcement';
@@ -29,29 +27,6 @@ $empty_en = $is_itstudio_news_page ? 'No news found.' : 'No announcements found.
$side_title_cn = $is_itstudio_news_page ? '要闻' : '重要公告'; $side_title_cn = $is_itstudio_news_page ? '要闻' : '重要公告';
$side_title_en = $is_itstudio_news_page ? 'Top Stories' : 'Important Announcements'; $side_title_en = $is_itstudio_news_page ? 'Top Stories' : 'Important Announcements';
$date_query = array();
$date_from_valid = '';
$date_to_valid = '';
if ($date_from !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $date_from)) {
$date_from_valid = $date_from . ' 00:00:00';
}
if ($date_to !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $date_to)) {
$date_to_valid = $date_to . ' 23:59:59';
}
if ($date_from_valid !== '' || $date_to_valid !== '') {
$range = array(
'inclusive' => true,
'column' => 'post_date',
);
if ($date_from_valid !== '') {
$range['after'] = $date_from_valid;
}
if ($date_to_valid !== '') {
$range['before'] = $date_to_valid;
}
$date_query[] = $range;
}
if ($tag_slug !== '') { if ($tag_slug !== '') {
$resolved_tag = get_term_by('slug', $tag_slug, 'post_tag'); $resolved_tag = get_term_by('slug', $tag_slug, 'post_tag');
if (!($resolved_tag instanceof WP_Term)) { if (!($resolved_tag instanceof WP_Term)) {
@@ -83,9 +58,6 @@ if ($keyword !== '') {
$list_query_args['itstudio_archive_extend_search'] = true; $list_query_args['itstudio_archive_extend_search'] = true;
$list_query_args['itstudio_archive_keyword'] = $keyword; $list_query_args['itstudio_archive_keyword'] = $keyword;
} }
if (!empty($date_query)) {
$list_query_args['date_query'] = $date_query;
}
if ($tag_slug !== '') { if ($tag_slug !== '') {
$list_query_args['tax_query'] = array( $list_query_args['tax_query'] = array(
array( array(
@@ -137,44 +109,8 @@ $featured_ids = array_slice(array_values(array_unique($featured_ids)), 0, 4);
</header> </header>
<div class="news-archive-tools"> <div class="news-archive-tools">
<form class="news-archive-filter-form" method="get" action="<?php echo esc_url($archive_url); ?>">
<?php if ($keyword !== '') : ?>
<input type="hidden" name="q" value="<?php echo esc_attr($keyword); ?>">
<?php endif; ?>
<div class="news-archive-filter-fields">
<label class="news-archive-filter-field">
<span data-cn="&#21457;&#24067;&#26102;&#38388;&#36215;" data-en="From">&#21457;&#24067;&#26102;&#38388;&#36215;</span>
<input type="date" name="date_from" value="<?php echo esc_attr($date_from); ?>">
</label>
<label class="news-archive-filter-field">
<span data-cn="&#21457;&#24067;&#26102;&#38388;&#27490;" data-en="To">&#21457;&#24067;&#26102;&#38388;&#27490;</span>
<input type="date" name="date_to" value="<?php echo esc_attr($date_to); ?>">
</label>
<label class="news-archive-filter-field news-archive-filter-tag">
<span data-cn="&#26631;&#31614;" data-en="Tag">&#26631;&#31614;</span>
<select name="tag">
<option value="" data-cn="&#20840;&#37096;&#26631;&#31614;" data-en="All tags">&#20840;&#37096;&#26631;&#31614;</option>
<?php foreach ($available_tags as $tag_option) : ?>
<option value="<?php echo esc_attr($tag_option->slug); ?>" <?php selected($tag_slug, $tag_option->slug); ?>>
<?php echo esc_html($tag_option->name); ?>
</option>
<?php endforeach; ?>
</select>
</label>
</div>
<button type="submit" data-cn="&#31579;&#36873;" data-en="Apply">&#31579;&#36873;</button>
</form>
<form class="news-archive-search" method="get" action="<?php echo esc_url($archive_url); ?>"> <form class="news-archive-search" method="get" action="<?php echo esc_url($archive_url); ?>">
<?php if ($date_from !== '') : ?> <div class="news-archive-search-controls">
<input type="hidden" name="date_from" value="<?php echo esc_attr($date_from); ?>">
<?php endif; ?>
<?php if ($date_to !== '') : ?>
<input type="hidden" name="date_to" value="<?php echo esc_attr($date_to); ?>">
<?php endif; ?>
<?php if ($tag_slug !== '') : ?>
<input type="hidden" name="tag" value="<?php echo esc_attr($tag_slug); ?>">
<?php endif; ?>
<input <input
type="search" type="search"
name="q" name="q"
@@ -186,6 +122,21 @@ $featured_ids = array_slice(array_values(array_unique($featured_ids)), 0, 4);
data-cn-aria-label="搜索文章或发布者" data-cn-aria-label="搜索文章或发布者"
data-en-aria-label="Search title or author" data-en-aria-label="Search title or author"
> >
<select
name="tag"
class="news-archive-search-tag"
aria-label="<?php esc_attr_e('Filter by tag', 'itstudio'); ?>"
data-cn-aria-label="按标签筛选"
data-en-aria-label="Filter by tag"
>
<option value="" data-cn="全部标签" data-en="All tags">全部标签</option>
<?php foreach ($available_tags as $tag_option) : ?>
<option value="<?php echo esc_attr($tag_option->slug); ?>" <?php selected($tag_slug, $tag_option->slug); ?>>
<?php echo esc_html($tag_option->name); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" data-cn="搜索" data-en="Search">搜索</button> <button type="submit" data-cn="搜索" data-en="Search">搜索</button>
</form> </form>
</div> </div>
@@ -279,8 +230,6 @@ $featured_ids = array_slice(array_values(array_unique($featured_ids)), 0, 4);
'add_args' => array_filter( 'add_args' => array_filter(
array( array(
'q' => $keyword, 'q' => $keyword,
'date_from' => $date_from,
'date_to' => $date_to,
'tag' => $tag_slug, 'tag' => $tag_slug,
), ),
static function ($value) { static function ($value) {
@@ -412,4 +361,3 @@ $featured_ids = array_slice(array_values(array_unique($featured_ids)), 0, 4);
<?php endif; ?> <?php endif; ?>
<?php get_footer(); ?> <?php get_footer(); ?>
+65 -75
View File
@@ -636,38 +636,50 @@
.news-archive-tools { .news-archive-tools {
margin-top: 14px; margin-top: 14px;
display: grid; display: block;
grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
gap: 12px;
align-items: end;
} }
.news-archive-filter-form { .news-archive-search {
display: grid; display: grid;
grid-template-columns: minmax(0, 1fr) auto; grid-template-columns: minmax(280px, 560px) auto;
gap: 8px; gap: 8px;
align-items: end; align-items: end;
justify-content: end;
} }
.news-archive-filter-fields { .news-archive-search-controls {
display: grid; display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-columns: minmax(0, 1fr) minmax(116px, 170px);
gap: 8px; gap: 8px;
} }
.news-archive-filter-field { .news-archive-search input[type="search"] {
display: grid; appearance: none;
gap: 4px; -webkit-appearance: none;
width: 100%;
height: 36px;
border: 1px solid var(--border-default);
border-radius: var(--radius-sm);
background: color-mix(in srgb, var(--bg-card) 90%, transparent);
color: var(--text-primary);
padding: 0 11px;
font-size: 0.88rem;
} }
.news-archive-filter-field span { .news-archive-search input[type="search"]::-webkit-search-decoration,
font-size: 0.72rem; .news-archive-search input[type="search"]::-webkit-search-cancel-button,
color: var(--text-secondary); .news-archive-search input[type="search"]::-webkit-search-results-button,
font-family: var(--font-mono); .news-archive-search input[type="search"]::-webkit-search-results-decoration {
-webkit-appearance: none;
appearance: none;
} }
.news-archive-filter-form input[type="date"], .news-archive-search input[type="search"]:focus {
.news-archive-filter-form select { outline: none;
border-color: var(--color-primary);
}
.news-archive-search select {
width: 100%; width: 100%;
height: 36px; height: 36px;
border: 1px solid var(--border-default); border: 1px solid var(--border-default);
@@ -678,48 +690,7 @@
font-size: 0.85rem; font-size: 0.85rem;
} }
.news-archive-filter-form input[type="date"]:focus, .news-archive-search select:focus {
.news-archive-filter-form select:focus {
outline: none;
border-color: var(--color-primary);
}
.news-archive-filter-form button {
height: 36px;
padding: 0 12px;
border: 1px solid var(--border-default);
border-radius: var(--radius-sm);
background: transparent;
color: var(--text-primary);
font-size: 0.86rem;
font-weight: 600;
cursor: pointer;
}
.news-archive-filter-form button:hover {
border-color: var(--color-primary);
color: var(--color-primary);
}
.news-archive-search {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
align-self: end;
}
.news-archive-search input[type="search"] {
width: 100%;
height: 36px;
border: 1px solid var(--border-default);
border-radius: var(--radius-sm);
background: transparent;
color: var(--text-primary);
padding: 0 11px;
font-size: 0.88rem;
}
.news-archive-search input[type="search"]:focus {
outline: none; outline: none;
border-color: var(--color-primary); border-color: var(--color-primary);
} }
@@ -741,20 +712,42 @@
color: var(--color-primary); color: var(--color-primary);
} }
html:not([data-theme="dark"]) .news-archive-filter-form input[type="date"], html:not([data-theme="dark"]) .news-archive-search select {
html:not([data-theme="dark"]) .news-archive-filter-form select {
color-scheme: light; color-scheme: light;
} }
[data-theme="dark"] .news-archive-filter-form input[type="date"], html:not([data-theme="dark"]) .news-archive-search input[type="search"] {
[data-theme="dark"] .news-archive-filter-form select { color-scheme: light;
}
[data-theme="dark"] .news-archive-search input[type="search"] {
background: color-mix(in srgb, var(--bg-card) 92%, #000 8%) !important;
color: var(--text-primary) !important;
-webkit-text-fill-color: var(--text-primary) !important;
color-scheme: dark;
}
[data-theme="dark"] .news-archive-search input[type="search"]:-webkit-autofill,
[data-theme="dark"] .news-archive-search input[type="search"]:-webkit-autofill:hover,
[data-theme="dark"] .news-archive-search input[type="search"]:-webkit-autofill:focus,
[data-theme="dark"] .news-archive-search input[type="search"]:autofill {
-webkit-text-fill-color: var(--text-primary) !important;
-webkit-box-shadow: 0 0 0 1000px color-mix(in srgb, var(--bg-card) 92%, #000 8%) inset !important;
box-shadow: 0 0 0 1000px color-mix(in srgb, var(--bg-card) 92%, #000 8%) inset !important;
background: color-mix(in srgb, var(--bg-card) 92%, #000 8%) !important;
border-color: var(--border-default) !important;
caret-color: var(--text-primary) !important;
transition: background-color 9999s ease-out 0s !important;
}
[data-theme="dark"] .news-archive-search select {
background: color-mix(in srgb, var(--bg-card) 92%, #000 8%); background: color-mix(in srgb, var(--bg-card) 92%, #000 8%);
color: var(--text-primary); color: var(--text-primary);
color-scheme: dark; color-scheme: dark;
} }
[data-theme="dark"] .news-archive-filter-form select option, [data-theme="dark"] .news-archive-search select option,
[data-theme="dark"] .news-archive-filter-form select optgroup { [data-theme="dark"] .news-archive-search select optgroup {
background-color: #0f1724; background-color: #0f1724;
color: var(--text-primary); color: var(--text-primary);
} }
@@ -1073,21 +1066,18 @@ html:not([data-theme="dark"]) .news-archive-filter-form select {
margin-top: 14px; margin-top: 14px;
} }
.news-archive-tools { .news-archive-search {
grid-template-columns: 1fr; grid-template-columns: minmax(0, 1fr) auto;
}
.news-archive-filter-form {
grid-template-columns: 1fr;
align-items: stretch; align-items: stretch;
} }
.news-archive-filter-fields { .news-archive-search-controls {
grid-template-columns: 1fr; grid-template-columns: minmax(0, 1fr) minmax(106px, 132px);
} }
.news-archive-search { .news-archive-search button {
grid-template-columns: 1fr; min-width: 62px;
padding: 0 10px;
} }
.news-story { .news-story {