Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改WordPress循环以显示类别_Php_Wordpress_Loops - Fatal编程技术网

Php 更改WordPress循环以显示类别

Php 更改WordPress循环以显示类别,php,wordpress,loops,Php,Wordpress,Loops,我有一个简单的WordPress循环来获取100篇最新帖子。我如何根据我所属的类别更改此选项以动态显示帖子 <?php // the query $wpb_all_query = new WP_Query(array( 'post_type' => 'post', 'post_status' => 'publish', 'post-no' => 100)); ?> <?php

我有一个简单的WordPress循环来获取100篇最新帖子。我如何根据我所属的类别更改此选项以动态显示帖子

  <?php
    // the query
    $wpb_all_query = new WP_Query(array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'post-no' => 100));
    ?>
    <?php if ($wpb_all_query->have_posts()) :
        while ($wpb_all_query->have_posts()) : $wpb_all_query->the_post(); ?>
            <img class="card-img-top bottom-line mb-2 lozad "
                             data-src="<?php the_post_thumbnail_url(); ?>"
                             alt="<?php the_title(); ?>"/>
        <?php endwhile; ?>
    <?php else : ?>

"
alt=”“/>

如果您的意思是您在类别存档页面上,则此代码将起作用:

// gets the category information from the archive page
$cat = get_the_category();

// the query
$wpb_all_query = new WP_Query(array(
    'post_type' => 'post',
    'post_status' => 'publish',
    // queries for posts that have that category
    'cat' => $cat[0]->cat_ID,
    'post-no' => 100));

你好@katie,很抱歉耽搁了,我是说当我在一个类别中只显示类别帖子时。我会试试你的答案,看看我能做些什么