我要根据年份过滤帖子。如果该年没有职位,则尝试消除该选项。我已经尝试了一些基本条件,但似乎无法使其正常运行。
这是我的简单尝试之一。
<?php if($query) {echo $year;} ?></option>
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
<?php
$oldY = 2013;
$currY = (int) date('Y');
$yList = array();
for($i=$currY;$i>=$oldY;$i--){
array_push($yList,$i);
}
?>
<div class="arch-filter">
<div class="filter-table">
<div class="filter-text">
Filter Results:
</div>
<div class="filter-option year-option">
<select id="yearSel">
<?php foreach($yList as $year){ ?>
<option value="<?php if($query) {echo $year; }?>">
<?php if($query) {echo $year; } ?></option>
<?php } ?>
</select>
</div>
<div class="filter-button">
<a id="sel-filter" href="<?php echo $current_url ?>/?yr=<?php echo end($yList) ?>">Apply</a>
</div>
</div>
<script>
$('.filter-table select').change(function(){
console.log('hello');
var link = "<?php echo $current_url ?>/?yr=";
link = link.concat($("#yearSel").val());
console.log(link);
$('#sel-filter').attr('href',link);
});
</script>
</div>
</div>
</div>
<?php
$p_count = 0;
$i =0;
$i++;
if (have_posts()) : while (have_posts()) : the_post();
//if a specific array value exists within a post
$term_list = wp_get_post_terms($post->ID, 'location', array("fields" => "all"));
foreach($term_list as $term_single) {
$country=$term_single->slug;
}
$cats = array();
$cat_slug = '';
$cat_id = '';
foreach (get_the_category($post_id) as $c) {
$cat = get_category($c);
if($cat->parent == 0){
$cat_slug = $cat->slug;
$cat_id = $cat->term_id;
}
array_push($cats, $cat->name);
}
$cat_data = get_option("category_$cat_id");
$color_code = '';
if(isset($cat_data['extra1'])){
$color = $cat_data['extra1'];
}
if (sizeOf($cats) > 0) {
$post_categories = implode(' / ', $cats);
}
else {
$post_categories = 'Not Assigned';
}
这是一个简单的想法,除了其他条件之外,我还必须使它起作用。这可能比我想的要容易得多。