从类别 - WordPress 中选择帖子


Select posts from Category - Wordpress

我正在尝试从类别中过滤帖子。

此类别称为"图像">

我有下面的代码:

<div id="owl-images" class="owl-carousel">
    <?php query_posts('category_name=images'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <?php
      $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );?>
      <a href='<?php echo $src[0]; ?>' data-lightbox="image-77" data-title="<?php the_title() ?>">
      <div class="item">
        <div class="lazyOwl" style="background:url(<?php echo $src[0]; ?>) no-repeat center center;background-size:cover;height:300px;" alt=""></div>
      </div>
    </a>
    <?php endwhile; endif; ?>
  </div>

问题是:

  • 它显示来自其他类别的一些帖子
  • 它不显示类别"图像"中的所有帖子

代码有什么问题?

PS:我看到了这个答案,它没有帮助。保持不变。

此致敬意。

你应该

尝试

猫=cat_id

而不是

category_name

对于更改,您的默认显示每页帖子:

转到设置 ->阅读 -> 博客页面

尝试这样做

query_posts( array ( 'category_name' => 'images' ) ); 

在这种情况下,您需要传递类别图像的辅助信息网络。

您也可以尝试使用这个

$catIDs = get_cat_ID('images');
query_posts("cat=$catIDs");

使用category__in并传递您的类别 ID

<?php query_posts('category__in=cat_id'); ?>