0

我一直在寻找并且无法找到可行的解决方案。这是示例:

我创建了一个名为“广告”的自定义帖子类型。目标是能够在广告下创建帖子并将它们显示在所需的模板中。我能够做到这一点,但我创建了 3 个自定义类别并且无法将其用于过滤。

我的代码是:

<?php query_posts('post_type=ads&posts_per_page=4&tag=home-above&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>



      <?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID) ) {
      $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full ); ?>
        <img class="has-tip tip-top" data-width="210" title="<?php the_field('hover_text'); ?>" src="<?php echo $thumbnail[0]; ?>" />

      <?php }else{ ?> 
      <img src="/DetroitSounds/wp-content/uploads/2013/01/youradhere.jpg" />
      <?php } ?> 



<?php endwhile; ?>  

<?php endif; wp_reset_query();?>

自定义类别名称是“首页上方”(slug=home-page-above)、“首页下方”(slug=home=page-below)和内页(slug=inner-pages)

在上面的代码中,我有一个标签,它实际上达到了我想要的效果,但恐怕后端可用性对客户端来说并不那么直接。

如果我什至正确使用该分类法,我也有点困惑?

任何想法都会很棒。谢谢

4

2 回答 2

1
$args = array( 'post_type' => 'ads',
               'posts_per_page'=>4,
               'tax_query' => array(
                      array(
                      'taxonomy' => 'type_taxonomy_name_here', //i don't know your taxonomy name
                      'field' => 'slug',
                      'terms' => 'home-page-above,home-page-below,inner-pages'
                      )
                )
            );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;
于 2014-09-02T13:59:11.847 回答
0

尝试使用category_name=your-category-slug,将您的第一行代码重写为:

<?php query_posts('post_type=ads&posts_per_page=4&category_name=home-page-above&orderby=rand'); ?>
于 2013-01-18T20:14:08.257 回答