Return new layout based on get_post_meta
-
I have a home page built where each section is made through a custom post type. Within that post type I created a custom meta box that has a dropdown menu to select the visual layout of that section. The dropdown consists of Main (first section on the homepage), Left (text on left, image on right), and Right (text on right, image on left).
I’m trying to set up my query to be something like this:
If dropdown is set to Main, use this code…
If dropdown is set to Left, use this code…
If dropdown is set to Right, use this code…This is where I’m at right now, but doesn’t work when I test it out.
<?php query_posts( array ('post_type' => 'home')); while ( have_posts() ) : the_post(); ?> <?php $thumb = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?> <?php if (get_post_meta($post->ID, 'layout-type', 'main' )) : ?> <!-- MAIN --> <div class="row home fullScreen" style="background-image: url(<?php echo $thumb; ?>);"> <div class="container"> <div class="col-sm-6 col-sm-offset-6"> <h1><?php the_title(); ?></h1> <p><?php the_content(); ?></p> <p><a href="<?php echo get_post_meta($post->ID, 'button-url', true) ?>" class="btn btn-primary btn-lg"><?php echo get_post_meta($post->ID, 'button-text', true) ?></a></p> </div> </div> <div class="scroll center-block"> <p>Scroll to Continue</p> <img src="<?php bloginfo('template_url'); ?>/images/scroll-arrow.png"> </div> </div> <?php endif; ?> <?php if (get_post_meta($post->ID, 'layout-type', 'left' )) : ?> <!-- LEFT --> <div class="row home fullScreen" style="background-image: url(<?php echo $thumb; ?>);"> <div class="container"> <div class="col-sm-6"> <h1><?php the_title(); ?></h1> <p><?php the_content(); ?></p> <p><a href="<?php echo get_post_meta($post->ID, 'button-url', true) ?>" class="btn btn-primary btn-lg"><?php echo get_post_meta($post->ID, 'button-text', true) ?></a></p> </div> </div> </div> <?php endif; ?> <?php if (get_post_meta($post->ID, 'layout-type', 'right' )) : ?> <!-- RIGHT --> <div class="row home fullScreen" style="background-image: url(<?php echo $thumb; ?>);"> <div class="container"> <div class="col-sm-6 col-sm-offset-6"> <h1><?php the_title(); ?></h1> <p><?php the_content(); ?></p> <p><a href="<?php echo get_post_meta($post->ID, 'button-url', true) ?>" class="btn btn-primary btn-lg"><?php echo get_post_meta($post->ID, 'button-text', true) ?></a></p> </div> </div> </div> <?php endif; ?> <?php endwhile; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Return new layout based on get_post_meta’ is closed to new replies.