Nested loop: foreach category > foreach custom post in that category
-
Hi,
I’m gonna cut to the chase. The pseudocode looks like this:
> for each existing category
> wrap in a slider markup
> for each custom post type with that category
> write in slide markupEffectively, this should get me as many sliders as categories, with as many slides as custom post types in that category. The code so far outputs all custom category posts in one slider. How can I get a slider for each category?
<?php $categories=get_categories(); foreach($categories as $category) { ?> <?php $catname=g et_category( 'Category1'); echo '<p>' . $catname . '</p>'?> <!-- et_pb_row > container --> <!-- <a class="arrow-left" href="#">left</a> <a class="arrow-right" href="#">right</a> --> <!-- swiper for each category --> <div class="swiper-container"> <div class="swiper-wrapper"> <!-- query that category --> <?php query_posts( 'post_type=human_section&category=' ); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="entry-content swiper-slide"> <?php the_content(); ?> </div> <!-- .entry-content --> <?php endwhile; endif; ?> <!-- <?php wp_reset_query(); ?> --> <?php rewind_posts(); ?> </div> <!-- .swiper-wrapper --> </div> <!-- .swiper-container --> <div class="pagination"></div> <? } // foreach($categories ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Nested loop: foreach category > foreach custom post in that category’ is closed to new replies.