使用PHP按类别筛选帖子
我正在Wordpress上建立一个网站,上面有一系列的活动(帖子),可以分为不同的城市(类别) 我的目标是能够过滤这些事件(职位)的城市(类别)他们出现 如何按类别筛选事件 任何帮助都将不胜感激,谢谢 分配给活动帖子的Wordpress类别使用PHP按类别筛选帖子,php,html,css,wordpress,twitter-bootstrap,Php,Html,Css,Wordpress,Twitter Bootstrap,我正在Wordpress上建立一个网站,上面有一系列的活动(帖子),可以分为不同的城市(类别) 我的目标是能够过滤这些事件(职位)的城市(类别)他们出现 如何按类别筛选事件 任何帮助都将不胜感激,谢谢 分配给活动帖子的Wordpress类别 Event=cat4 城市A=cat6 城市B=cat5 Uncategorized=cat7 <div class="row justify-content-center row-padding" id="
Event=cat4
城市A=cat6
城市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>
按城市筛选
为什么不创建一个自定义WordPress模板,例如country-posts-archive.php,并使用所需的过滤器实现自定义post查询呢
$categories_args = array(
'orderby' => 'menu_order', //prefered order
'taxonomy' => 'product_cat', // the taxonomy we want to get terms of
'exclude' => '17, 69', //exclude something
);
然后在wp post循环中使用它,也可以在orderby.php中使用它
或者,简单的非编码方式只是使用side插件,例如:
你也可以用一种有点棘手的方式来完成,用链接到归档页面的下拉列表填充,例如
www.website.com/category/your-category
您为隐藏/显示类别条目而编写的Javascript在哪里?“任何帮助都将不胜感激”-基于此,我们不知道您到底需要什么样的帮助。请去读。你需要问一些具体的问题。