我知道如何显示特定类别的帖子,但是我需要将某个类别的帖子分成两组,其中一组带有标签,而另一组没有标签。
示例:客户希望按服务类型显示服务提供商的列表,比方说“法律服务”。但是他们也想将其中一些标记为“推荐”。在未标记的标签之前,如何显示标记为推荐标签的标签?
我尝试通过标签搜索来标识和显示帖子,但没有找到我想要的内容。我不想添加另一个子类别,因为每个类别(例如“法律服务”)已经具有特定服务的子类别。这就是为什么我认为客户在输入帖子时最容易理解和管理“推荐”标签的原因。
<!-- Create list of links of each category -->
<?php
$subcategories = get_categories('&child_of=21&hide_empty'); // List subcategories of category '4' (even the ones with no posts in them)
echo '<ul class="resource-hub-sub-cats">';
foreach ($subcategories as $subcategory) {
echo sprintf('<li><a href="%s">%s</a></li>', get_category_link($subcategory->term_id), apply_filters('get_term', $subcategory->name));
}
echo '</ul>';
?>
<!--List posts with tag-->
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post(); ?>
<?php $tag_list = get_the_tag_list( $before, $sep, $after, $id );
echo get_the_tag_list('<p>Tags: ',', ','</p>');
?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile;
endif;
?>
<!--Display all posts of category-->
<?php
$args = array(
'posts_per_page' => 10,
'category__in' => array( 21 ),
);
$project = new WP_Query( $args );
if( $project->have_posts() ):
while( $project->have_posts() ):
$project->the_post();
?>
<p><strong><?php the_title(); ?></strong><br />
<p><?php the_content(); ?><br />
<?php if( get_field('provider_website') ): ?>
<a href="<?php the_field('provider_website'); ?>">Visit Website</a></p>
<?php endif; ?>
<?php
endwhile;
wp_reset_postdata();
else:
echo "<p>No providers in our database</p>";
endif;
?>