【发布时间】:2020-06-12 07:10:16
【问题描述】:
我创建了自定义帖子类型,我正在归档页面中显示帖子,但我想在 1 个页面中显示不同类别的帖子。像这样:
但是我的帖子目前是这样的
我怎样才能做到这一点?我进行了很多搜索,但没有找到任何解决方案。所以,这就是我在这里提出问题的原因。
这是我的代码:
<section class="careerBlogs">
<div class="container">
<div class="row with-gutters">
<?php
$args = array (
'post_type' => array( 'career' ),
'post_status' => array( 'publish' ),
'nopaging' => true,
'order' => 'ASC',
'orderby' => 'menu_order',
);
$templates = new WP_Query( $args );
if ( $templates->have_posts() ) {
while ( $templates->have_posts() ) {
$templates->the_post(); global $post;
$customVars = get_post_meta($post->ID, 'custom_vars', true);
if(!empty($customVars)){
$isRemotely = $customVars['remotely'];
}
// Categories
$categories = get_the_terms( $post->ID, 'career_category' );
foreach( $categories as $category ) { ?>
<div class="col-xs-12">
<div class="careerBlogs--title">Open Positions in <?= $category->name; ?></div>
</div>
<?php } ?>
<div class="col-xl-12">
<div class="card mb-4">
<a href="<?= get_the_permalink(); ?>" class="card-link">
<div class="card-info">
<div class="card-title"><?= get_the_title(); ?></div>
<div class="location">
<span>Lahore</span>/<span><?= $isRemotely ? 'Remote' : '' ?></span>
</div>
</div>
</a>
</div>
</div>
<?php } } else {
echo 'no posts to show';
}
wp_reset_postdata();
?>
</div>
</div>
</section>
它在我的archive-career.php 页面中。你能帮我实现吗?我被困在这里了
【问题讨论】:
标签: php wordpress wordpress-theming custom-wordpress-pages