wordpress - 如何在 Wordpress 中显示投资组合
问题描述
我能够使用自定义帖子类型和分类法显示所有内容,但是当我尝试创建分类法类别的过滤器时,我认为我遗漏了一些东西,因此,我只能在没有过滤器的情况下显示投资组合。下面是我的代码,我肯定遗漏了一些东西,但不确定是什么。
/**Case Study Custom Post Type**/
function casestudy_posttype() {
$args = array(
'public' => true,
'label' => ( 'Case Study'),
'menu_icon' => 'dashicons-category',
"supports" => [ "title", "editor", "thumbnail" ],
);
register_post_type( 'casestudy', $args );
}
add_action( 'init', 'casestudy_posttype' );
add_action( 'init', 'casestudy_cates' );
function casestudy_cates() {
register_taxonomy(
'casestudy-cates',
'casestudy',
array(
'label' => ( 'Case Study Categories' ),
'rewrite' => array( 'slug' => 'casestudy-category' ),
'hierarchical' => true,
)
);
}
/**END CUSTOM POST TYPE FOR case study **/
显示在页面上
<!-- case_study_area -->
<div class="case_study_area case_page">
<div class="container">
<div class="row">
<div class="col-xl-12">
<div class="portfolio-menu text-center">
<?php global $post;
$taxonomy = 'casestudy-cates';
$terms = wp_get_post_terms($post->ID, $taxonomy);
if ($terms && !is_wp_error($terms)) :?>
<button class="active" data-filter="*">All</button>
<?php
foreach ($terms as $serv_terms) :
?>
<li class="tab-<?php echo $count ?>"><?php echo $serv_terms->name; ?>
</li>
<button data-filter="<?php echo $serv_terms->slug; ?>"><?php echo $serv_terms->name; ?></button>
<?php
endforeach ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="row grid">
<?php
$args = array('post_type' => 'casestudy', 'order' => 'ASC');
query_posts($args);
while (have_posts()) : the_post();
global $post;
?>
<div class="col-xl-4 grid-item">
<div class="single_case">
<div class="case_thumb">
<?php the_post_thumbnail()?>
</div>
<div class="case_heading">
<?php
global $post;
$taxonomy = 'casestudy-cates';
$terms = wp_get_post_terms($post->ID, $taxonomy);
if ($terms && !is_wp_error($terms)) :?>
<?php foreach ($terms as $serv_terms) : ?>
<span><?php echo $serv_terms->name; ?></span>
<?php endforeach ?>
<?php endif; ?>
<h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
<?php foreach ($terms as $key=>$term) :?>
<?php
$args = array('post_type' => 'casestudy', 'order' => 'ASC', 'tax_query' => array(
array(
'taxonomy' => 'casestudy_cates', 'field' => 'slug', 'terms' => $term->slug)
));
query_posts($args);
while (have_posts()) : the_post();
?>
<div
class="col-xl-4 grid-item <?php echo $term->slug;?>">
<div class="single_case">
<div class="case_thumb">
<?php the_post_thumbnail()?>
</div>
<div class="case_heading">
<?php
global $post;
$taxonomy = 'casestudy-cates';
$terms = wp_get_post_terms($post->ID, $taxonomy);
if ($terms && !is_wp_error($terms)) :?>
<?php foreach ($terms as $serv_terms) : ?>
<span><?php echo $serv_terms->name; ?></span>
<?php endforeach ?>
<?php endif; ?>
<h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
</div>
</div>
</div>
<?php endwhile; wp_reset_query();?>
<?php endforeach;?>
</div>
</div>
</div>
<!-- /case_study_area -->
解决方案
推荐阅读
- javascript - 使用部分匹配过滤/搜索表格 - HTML & Javascript
- node.js - 连接Redis的API在cURL调用时返回值,但在axios调用时不返回
- python - Python图像处理叶分割
- mapbox - Mapbox 显示来自我的 Internet 服务提供商 (ISP) IP 地址的位置
- javascript - 有没有办法通过单击复选框来更改和显示单选按钮的值
- java - 如何为这个基于文本的记忆匹配游戏实现一个选项来拥有多个尺寸的棋盘?
- ansible - 在存储库之间重用 Ansible playbook 逻辑
- python - 关于如何处理coco的测试数据集的问题
- javascript - aframe 分屏转单屏效果
- text - 将连字符字典批量导入 InDesign