Multi nested if conditions & custom values in blog posts
-
Hi there,
I am trying to pull images into my wordpress page using 3 if conditions which looks for 2 different custom values in my blog post.
In layman's words, [IF] custom_field1="A", echo="B" [ELSE] [IF] custom_field2="C", echo="D" [ELSE] [IF] image_exists_in_post, echo="E" [ELSE] echo="F" [END]
Now here is my proper PHP code,
<?php query_posts('showposts=1&cat=4'); ?> <?php while (have_posts()) : the_post(); ?> <?php $id =$post->ID; $the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id"); $pattern = '!<img.*?src="(.*?)"!'; preg_match_all($pattern, $the_content, $matches); $image_src = $matches['1'][0]; ?> <div> <?php $variable = get_post_custom_values("cValue"); if (isset($variable[0])) { ?> <img src="<?php $variable = get_post_custom_values("cValue"); echo $variable[0]; ?> <?php } else {?> <?php $values = get_post_custom_values("Image"); if (isset($values[0])) { ?> <img src="<?php $values = get_post_custom_values("Image"); echo $values[0]; ?> <?php } else {?> <?php if($image_src != '') { ?> <img src="<?php echo bloginfo('template_url'); ?> <?php } else {?> <img src="<?php echo bloginfo('template_url'); ?>/images/no-attachment_headline.gif"> <?php }?> <?php }?> <?php }?> </div> <?php endwhile; ?> <?php wp_reset_query(); ?>
I’ve omitted some of my original code just to save some confusion.
Is it a simple problem of syntax issues?
- The topic ‘Multi nested if conditions & custom values in blog posts’ is closed to new replies.