php - 显示特定自定义分类类型的帖子
问题描述
我有一个custom taxonomy
被叫Topics
分配给custom post type
被叫blog
。
Topics
目前看起来像这样:
现在,在 上/blog
,我有一个select
如下所示的过滤器:
// submit form on select change
$('.blogFilter .blogFilter__form').on('change', function() {
$(this).submit();
});
<?php
$terms = get_terms(
array(
'taxonomy' => 'Topics',
'hide_empty' => true,
)
); ?>
<form class="blogFilter__form" role="search" action="<?php echo site_url('/blog/'); ?>" method="get">
<select class="globalFilter">
<option class="globalFilter__option" value="">Topics</option>
<?php
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
$term_name = get_term( $term )->name;?>
<option class="globalFilter__option" value="<?php echo $term_link; ?>">
<?php echo $term_name; ?>
</option>
<?php } ?>
</select>
</form>
Idea being that when the select
option changes, it will submit the form and display posts that matches that Topic
. 即,如果我News
从下拉列表中选择,它只会显示带有topic
of 的帖子News
。
Currently, when choose News
, it shows me all posts.
我遇到的最接近的解决方案是标签模板。但这似乎不适用于custom taxonomies
.
我想要实现的是以下经验:
- 用户从下拉列表中选择选项并被重定向到包含所有这些帖子的页面,即
/blog/topics/news/
. 现在,value
我的option
标签中的 ie 确实渲染了slugs
ie/topics/news/
。然而,这只是吐出帖子的文字。topic-template
如果我希望设置这些样式并编写自定义标记,我在 codex中看不到 a 行中的任何内容吗?
解决方案
推荐阅读
- struct - 在通用 lisp 中将结构传递给宏的类型错误
- vbscript - Vbscript Sendkeys 在某些应用程序中不起作用
- php - WordPress 会话在主页之外无法正常工作
- vue.js - 我希望能够在从后端获得的图像上绘制框
- javascript - 'this' 在 Javascript 的扩展类中返回未定义
- python - python/django中的if语句
- flutter - 有什么简单的方法可以通过 Firebase Auth 在 Flutter 中“使用 Google Play 游戏登录”
- javascript - 我可以在 React 中使用柯里化来进行后续的 API 调用吗?
- django - django 容器无法访问 postgres 容器
- python-3.x - 操作熊猫数据框中的列