• The following code shows the sloppy way of accomplishing what I need. I essentially repeat the same code for as many tiers as I want to support. My logic isn’t strong enough to figure out a while loop mixed in with this. Any help would be greatly appreciated.

    <?php $tier1 = get_pages('hierarchical=0&parent=8&sort_column=menu_order');
    				foreach ( $tier1 as $page ) { ?>
    
    					<div class="tier_unit">1</div>
    
    					<div class="tier1">
    						<div class="tier_title">
    							<?php echo $page->post_title; ?>
    						</div>
    
    						<div class="page_type">
    							<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    						</div>
    					</div>
    
    				<?php $tier2 = get_pages('hierarchical=0&parent='.$page->ID.'&sort_column=menu_order');
    					foreach ( $tier2 as $page ) { ?>
    
    						<div class="tier_unit">2</div>
    
    						<div class="tier2">
    							<div class="tier_title">
    								<?php echo $page->post_title; ?>
    							</div>
    
    							<div class="page_type">
    								<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    							</div>
    
    						</div>
    
    					<?php $tier3 = get_pages('hierarchical=0&parent='.$page->ID.'&sort_column=menu_order');
    						foreach ( $tier3 as $page ) { ?>
    
    							<div class="tier_unit">3</div>
    
    							<div class="tier3">
    								<div class="tier_title">
    									<?php echo $page->post_title; ?>
    								</div>
    
    								<div class="page_type">
    									<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    								</div>
    
    							</div>
    
    						<?php $tier4 = get_pages('hierarchical=0&parent='.$page->ID.'&sort_column=menu_order');
    							foreach ( $tier4 as $page ) { ?>
    
    								<div class="tier_unit">4</div>
    
    								<div class="tier4">
    									<div class="tier_title">
    										<?php echo $page->post_title; ?>
    									</div>
    
    									<div class="page_type">
    										<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    									</div>
    
    								</div>
    
    							<?php $tier5 = get_pages('hierarchical=0&parent='.$page->ID.'&sort_column=menu_order');
    								foreach ( $tier5 as $page ) { ?>
    
    									<div class="tier_unit">5</div>
    
    									<div class="tier5">
    										<div class="tier_title">
    											<?php echo $page->post_title; ?>
    										</div>
    
    										<div class="page_type">
    											<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    										</div>
    
    									</div>
    
    									<?php $tier6 = get_pages('hierarchical=0&parent='.$page->ID.'&sort_column=menu_order');
    										foreach ( $tier6 as $page ) { ?>
    
    											<div class="tier_unit">6</div>
    
    											<div class="tier6">
    												<div class="tier_title">
    													<?php echo $page->post_title; ?>
    												</div>
    
    											<div class="page_type">
    												<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    											</div>
    
    											</div>
    
    											<?php $tier7 = get_pages('hierarchical=0&parent='.$page->ID.'&sort_column=menu_order');
    												foreach ( $tier7 as $page ) { ?>
    
    													<div class="tier_unit">7</div>
    
    													<div class="tier7">
    
    														<div class="tier_title">
    															<?php echo $page->post_title; ?>
    														</div>
    
    														<div class="page_type">
    															<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    														</div>
    
    													</div>
    
    										<?php } //Tier 7 ?>
    
    									<?php } //Tier 6 ?>
    
    								<?php } //Tier 5 ?>
    
    							<?php } //Tier 4 ?>
    
    						<?php } //Tier 3 ?>
    
    					<?php } //Tier 2 ?>
    
    				<?php } //Tier 1 ?>
Viewing 1 replies (of 1 total)
  • Thread Starter icebane

    (@icebane)

    I sold this and feel like an idiot!
    I combined get_pages with get_ancestors to count the tiers and it works flawlessly!!!

    <?php $hierarchy = get_pages('child_of=8&sort_column=menu_order');
    
    			foreach ( $hierarchy as $page ) {
    				$acount = count(get_ancestors($page->ID, 'page'));
    
    			?>
    
    			<div class="tier_unit"><?php echo $acount; ?></div>
    
    				<div class="tier<?php echo $acount; ?>">
    					<div class="tier_title">
    						<?php echo $page->post_title; ?>
    					</div>
    
    					<div class="page_type">
    						<img src="/wp-content/uploads/<?php the_field('page_type',$page->ID); ?>.jpg" />
    					</div>
    				</div>
    
    			<?php } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Loop through all children, and children's children, up to x tiers’ is closed to new replies.