Dispaly unordered list dynamically?
-
I have this bit of code that displays out a list of categories in a four up grid. This code works perfectly. I also have a bit of code under this code that displays a similar grid but with different markup.(see second code snippet)I actually need to display the second bit of code with the same mark up as the top bit of code. Meaning I need to display the second bit of code as a
<ul>
with repeating<li>
items in it. So if I use the<ul>
markup with the second bit of code it will just keep looping<ul><li></li></ul>
instead of just having the appear once with repeating items inside. I’m a bit of a n00b so any help would be greatly appreciated.<?php get_template_part( 'content' ); global $wp_query; $query_object = $wp_query->get_queried_object(); $post_type = $wp_query->query_vars['post_type']; $queried_object = get_queried_object(); $term_id = $query_object->term_id; $taxonomyName = "molding_profile_category"; $termchildren = get_term_children( $term_id, $taxonomyName ); if ($termchildren) { //echo '<hr style="border-width:1px; border-color:#AD7856;">'; echo '<ul style="padding:0px;" class="block-grid four-up mobile-one-up">'; $args = array( 'type' => $post_type, 'hide_empty' => 1, 'orderby' => 'name', 'order' => 'ASC', 'taxonomy' => $taxonomyName, ); $categories = get_categories($args); $categories = wp_list_filter($categories,array('parent'=> $term_id)); foreach($categories as $category) { // setup the cateogory ID $cat_id = $category->term_id; // Get category name $cat_name = $category->name; // Get category count $cat_count = $category->count; //get the category url $cat_url = get_term_link( $category->slug, $taxonomyName ); // Grab ACF Fields $cat_attachment_id = get_field('category_image', 'molding_profile_category_' . $cat_id ); $cat_size = "full"; // (thumbnail, medium, large, full or custom size) $cat_image = wp_get_attachment_image_src( $cat_attachment_id, $cat_size ); echo '<li style="text-align:center;">'; echo '<a style="color:#AD7856;" href="'.$cat_url.'">'; echo '<p class="cat-title">'; echo '<div><hr style="border-color:#AD7856"></div>'; echo $cat_name; echo '</p>'; //echo '<hr style="margin-top:0px;">'; // Print cat thumb if ($cat_image) { echo '<div class="twelve columns cat-img-wrapper"><img class="cat-img" src="'.$cat_image[0].'" alt="'.$cat_name.'"></div>'; } echo '</a>'; echo '</li>'; } echo '</ul>'; }
if (get_query_var('molding_profile_category')) { $taxonomy_term_id = $wp_query->queried_object_id; $taxonomy = 'molding_profile_category'; $unwanted_children = get_term_children($taxonomy_term_id, $taxonomy); $unwanted_post_ids = get_objects_in_term($unwanted_children, $taxonomy); // merge with original query to preserve pagination, etc. query_posts( array_merge( array( 'post__not_in' => $unwanted_post_ids ), $wp_query->query) ); } if(have_posts()) { while (have_posts()) : the_post(); ?> <div class="three columns left for-mobile"> <div><hr style="border-color:#AD7856"></div> <div class="twelve columns mp-img-wrapper"> <div class="molding-wrapper"> <a href="<?php the_permalink(); ?>"> <img class="mp-img" src="<?php the_field('profile_thumb_image'); ?>" /> </a> </div> </div> <div class="mp-info"> <p class="mp-title"><a style="color:#3F7091;" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> <p class="mp-dim"><?php the_field('profile_dimensions'); ?></p> </div> </div> <?php endwhile; } ?>
- The topic ‘Dispaly unordered list dynamically?’ is closed to new replies.