Php 仅显示WordPress中特定类别的标记

Php 仅显示WordPress中特定类别的标记,php,wordpress,loops,tags,custom-post-type,Php,Wordpress,Loops,Tags,Custom Post Type,我目前有一个自定义的帖子类型,名为Sectors。这也有分类。 在这里,我有单独的扇区,可以附加标签 我目前正在尝试做的是,将标签添加到某个扇区,并且标签扇区将成为其类别页面中的“特色扇区” 使用下面的代码,在我的taxonomy-sectors.php页面上,我可以做到这一点: <?php $args = array( 'tag_slug__and' => array('sector1'), 'post_type' => arra

我目前有一个自定义的帖子类型,名为Sectors。这也有分类。

在这里,我有单独的扇区,可以附加标签

我目前正在尝试做的是,将标签添加到某个扇区,并且标签扇区将成为其类别页面中的“特色扇区”

使用下面的代码,在我的taxonomy-sectors.php页面上,我可以做到这一点:

    <?php 
    $args = array(
      'tag_slug__and' => array('sector1'),
      'post_type' => array( 'sectors' )
      );
    $loop = new WP_Query( $args );
    while ($loop->have_posts() ) : $loop->the_post();
    ?>
    <a href="<?php echo get_permalink(); ?>">
     <?php echo "<div class='col-md-6' style='margin-bottom:20px;'>"; ?>
     <div class="row mobilemargin">
      <div class="categorytiletextsector1">
        <div class="col-md-6 col-sm-6 col-xs-12 nopr"><?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'sector1img hovereffect')); ?> </div>
        <div class="col-md-6 col-sm-6 col-xs-12">
          <div class="testdiv">
           <h5><?php the_title(); ?></h5>
           <p><?php the_excerpt(); ?></p>
         </div>
       </div>
     </div>
   </div>
   <?php echo "</div>"; ?>

 </a>
试试这个

<div class="col-md-6 col-sm-6 col-xs-12"> 
   <div class="testdiv"> 
          <h5><?php the_title(); ?></h5> 
          <p><?php the_excerpt(); ?></p> 
          <p><?php the_tags( 'Tags: ', ', ', '<br />' ); ?></p> 
   </div> 
</div>


您目前的查询,正如您已经找到的,将检索所有帖子,而不是特定于您正在查看的术语

如果我正确理解了你的问题,那么你想过滤显示在你正在查看的术语中的帖子。这可以通过使用
get\u queryed\u object\u ID()
获取当前术语ID并将其传递到
tax\u query
参数中来实现

更改:

$args = array(
    'tag_slug__and' => array('sector1'),
    'post_type' => array( 'sectors' )
);
致:


$args
数组中是否有可以使用的
cat
参数?我猜,但这不是只有当你选择你想要的类别。我的意思是,我想让它为我选择,因为我不能说“类别4”。如果这是愚蠢的道歉,我应该在哪里添加这个?有人吗?不太确定在何处执行此代码,尝试了一些地方,但如果不起作用,则不希望升级。如果希望在帖子中显示标记,请在taxonomy-sectors.php页面上使用此代码<代码>

这是什么。抱歉,但这是废话。出于某种原因,标记的项目现在没有显示在任何地方?现在根本不在任何类别页面上,有什么想法吗?
<div class="col-md-6 col-sm-6 col-xs-12"> 
   <div class="testdiv"> 
          <h5><?php the_title(); ?></h5> 
          <p><?php the_excerpt(); ?></p> 
          <p><?php the_tags( 'Tags: ', ', ', '<br />' ); ?></p> 
   </div> 
</div>
$args = array(
    'tag_slug__and' => array('sector1'),
    'post_type' => array( 'sectors' )
);
$args = array(
    'tag_slug__and' => array( 'sector1' ),
    'post_type'     => array( 'sectors' ),
    'tax_query'     => array(
        array(
            'taxonomy' => 'sectors',
            'terms'    => get_queried_object_id(),
        ),
    ),
);