如何按类别显示($ query-> have_posts())?

时间:2019-10-21 10:08:42

标签: wordpress

我有WP项目。

Search&Filter插件在result.php页面上显示我的搜索结果,就是这样-

if ($query->have_posts()) {
    ?>
<h4 class="offer__item-title">Items from Category_1</h4>
<span>I can find<?php echo $query->found_posts; ?> item (items)</span><br>

<div class="pagination"><?php next_posts_link('', $query->max_num_pages); ?></div>
<div class="nav-next"><?php previous_posts_link(''); ?></div>

<span class="category__span">Category Title</span>
<?php
    while ($query->have_posts()) {
        $query->the_post(); ?>

<div class="offer__item">
    <img src="<?php the_field('image'); ?>" alt="">
    <span class="category__span">Name_of_category</span>
    <span><?php the_title(); ?></span>
    <div>
        <button>Buy</button>
        <button>Information</button>
    </div>
</div>

<?php
    } ?>
<?php
} else {
        echo "</br> :(";
    }
?>

然后我需要在我的页面上显示所有按类别排序的类别和项目-

<span class="category__span">Category Title</span>
<div class="offer__item">
    <img src="<?php the_field('image'); ?>" alt="">
    <span class="category__span">Name_of_category</span>
    <span><?php the_title(); ?></span>
    <div>
        <button>Buy</button>
        <button>Information</button>
    </div>
</div>

<span class="category__span">Category Title2</span> 
<div class="offer__item">
    <img src="<?php the_field('image'); ?>" alt="">
    <span class="category__span">Name_of_category2</span>
    <span><?php the_title(); ?></span>
    <div>
        <button>Buy</button>
        <button>Information</button>
    </div>
</div>

<span class="category__span">Category Title3</span>
<div class="offer__item">
    <img src="<?php the_field('image'); ?>" alt="">
    <span class="category__span">Name_of_category3</span>
    <span><?php the_title(); ?></span>
    <div>
        <button>Buy</button>
        <button>Information</button>
    </div>
</div>

然后我需要$query->have_posts()内具有按类别排序的项目。谢谢!对不起,我的英语不好,我需要你的帮助!

0 个答案:

没有答案