【发布时间】:2021-06-23 06:33:01
【问题描述】:
我正在 Wordpress 中构建一个网站,其中包含一个事件(帖子)列表,可以分为不同的城市(类别)。
我的目标是能够按它们出现的城市(类别)过滤这些事件(帖子)。
如何按类别过滤事件?
任何帮助将不胜感激,谢谢。
分配给活动帖子的 Wordpress 类别
Event = cat4
City A = cat6
City B = cat5
Uncategorized = cat7
<div class="row justify-content-center row-padding" id="brands">
<div class="col-9">
<div class="row justify-content-center">
<div class="col-10">
<div class="animatedParent animateOnce">
<?php if( get_field('brands_title') ):?>
<h1 class="mb-3 animated fadeInUpShort"><span><?php the_field('events_title');?></span></h1>
<?php endif;?>
<?php if( get_field('brands_intro') ):?>
<h4 class="mb-5 animated fadeInUpShort"><?php the_field('events_intro');?></h4>
<?php endif;?>
</div>
</div>
<div class="col-1">
</div>
<div class="col-1 align-self-center animatedParent animateOnce" style="z-index:99;">
<div class="dropdown animated fadeInUpShort">
<button class="btn filter-button dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Filter by City
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">City A</a></li>
<li><a class="dropdown-item" href="#">City B</a></li>
<li><a class="dropdown-item" href="#">Uncategorized</a></li>
</ul>
</div>
</div>
</div>
<div class="row justify-content-center animatedParent animateOnce" data-sequence="100">
<?php
$brandPosts = new WP_Query('cat=4&posts_per_page=99');
if ($brandPosts->have_posts()) {
$i=1;
while ($brandPosts->have_posts()) {
$brandPosts->the_post();
?>
<div class="col-4 animated fadeIn mb-5 pb-3" data-id="<?php echo $i; ?>">
<div class="row justify-content-center">
<div class="col-12 text-center">
<a href="<?php the_permalink(); ?>"><img alt="<?php the_title(); ?>" src="<?php the_post_thumbnail_url(); ?>" class="img-fluid rounded-circle mb-3"></a>
</div>
</div>
<div class="row">
<div class="col-10 offset-2">
<a href="<?php the_permalink(); ?>"><h2 class="mb-0"><?php the_title(); ?></h2></a>
<p><?php echo excerpt(16); ?></p>
<a href="<?php the_permalink(); ?>" class="see-more">See More</a>
</div>
</div>
</div>
<?php
$i++;
}
} else {
//echo 'No content found';
}
wp_reset_postdata();
?>
</div>
</div>
</div>
【问题讨论】:
-
您为隐藏/显示类别条目而编写的 Javascript 在哪里?
-
“任何帮助都将不胜感激” - 基于此,我们不知道您需要确切什么样的帮助。请阅读How to Ask。您需要提出具体的问题。
标签: php html css wordpress twitter-bootstrap