Create a conditional logic inside an array
-
I am basically looking to tidy up my code. I have a custom post type with categories. I then have particular categories displaying on certain pages. I don’t want to repeat the same thing each time and only changing the category type. I want to create an if statement inside of the array but have no idea how to go about it. Open to any suggetions
Here is my code:
[ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]
<?php if( is_page('24655') ) : ?> <section> <ul id="thumbnailGrid"> <?php $args=array( 'testimonial-type' => '200-hours-testimonial', //this is what I change 'post_type' => 'testimonials', 'post_status' => 'publish', 'posts_per_page' => 10, ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li class="ft_promo col-md-3 col-sm-6"> <?php global $post; ?> <?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' ); ?> <img src="<?php echo $src[0]; ?>" /> <h3><?php the_title(); ?></h3> <p><?php the_content(); ?></p> <?php endwhile; } wp_reset_query(); ?> <div class="clearfix"></div> </section> <?php elseif (is_page('24732') || is_page('24794')): ?> <section>repeat as above etc. etc. etc.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Create a conditional logic inside an array’ is closed to new replies.