例如,我將有4個類別。對於每個類別,我會顯示5個最近的帖子。我將有類別,如早餐,甜點,午餐和美味的食物。每個類別都會有一個「全部看」鏈接,這樣用戶就可以看到所有的早餐類別信息。在主頁上,我會列出最近發佈的5篇帖子,當用戶點擊「查看全部」鏈接時,它會將它們鏈接到整個早餐類別。如果他們點擊「全部查看」,我想要在該類別的所有早餐。其他類別也一樣。 目前我的代碼看起來像這樣,但我堅持「看到所有」鏈接。我不知道如何將它鏈接到主類別。如何根據類別顯示所有帖子?
<?php
get_header();
?>
<!-- recipe -->
<section class="recipe-wrap">
\t <?php
\t /*
\t * Loop through Categories and Display Posts within
\t */
\t $post_type = 'recipe';
\t $category_link = get_category_link($cat->cat_ID);
\t
\t // Get all the taxonomies for this post type
\t $taxonomies = get_object_taxonomies(array('post_type' => $post_type));
\t
\t foreach($taxonomies as $taxonomy) :
\t
\t // Gets every "category" (term) in this taxonomy to get the respective posts
\t $terms = get_terms($taxonomy);
\t
\t foreach($terms as $term) : ?>
\t <div class="recipe-category owl-carousel-slide">
\t \t <div class="row">
\t \t \t <h2><?php echo $term->name; ?><a href="#">see all</a></h2>
\t
\t <div class="recipe-category-carousel owl-carousel owl-theme">
\t \t <?php
\t \t $args = array(
\t \t 'post_type' => $post_type,
\t \t 'posts_per_page' => 10, //show all posts
\t \t 'tax_query' => array(
\t \t array(
\t \t 'taxonomy' => $taxonomy,
\t \t 'field' => 'slug',
\t \t 'terms' => $term->slug,
\t \t )
\t \t )
\t \t
\t \t );
\t \t $posts = new WP_Query($args);
\t \t
\t \t if($posts->have_posts()): while($posts->have_posts()) : $posts->the_post(); ?>
\t <div class="item recipe-box">
\t \t <a href="<?php the_permalink(); ?>">
\t \t <img src="<?php echo(types_render_field('artwork', array('raw' => true))); ?>">
\t \t <p><?php the_title(); ?></p>
\t </a>
\t </div>
<?php endwhile; endif; ?>
\t \t \t </div>
\t \t \t
\t \t \t </section>
\t \t \t
\t \t \t <?php endforeach;
\t \t \t
\t \t \t endforeach; ?>
\t </div>
</div>
</div>
</section>
<!-- /recipe -->
<?php
get_footer();
?>
這不是一個[最小,完整,可驗證示例](https://stackoverflow.com/help/mcve)。請通過發佈一個最小的,完整的和可驗證的例子來幫助答覆者和未來的讀者。 –