php - Wordpress bringing in template_part based on custom field -


i have wordpress loop on index.php brings in specific template-part.

<?php if ( have_posts() ) : ?>    <?php /* start loop */ ?>     <?php while ( have_posts() ) : the_post(); ?>              <?php                 get_template_part( 'content' );             ?>          <?php endwhile; ?>          <div class="clearfix"></div>      <?php else : ?>          <?php get_template_part( 'no-results', 'index' ); ?>  <?php endif; ?> 

content.php has article blog post information (title, featured image, etc) specific html.

i have custom-field, extracss, applied each post through content.php values 'post-right' or 'post-left' (so can change css of individual posts).

content.php code

<?php $extracss = get_post_meta(get_the_id(),'extracss',true);  <article class="<?php echo $extracss?>">  

...

i want have 2 different template_parts can called loop depending on custom-field or value applied post.

ex. if post has extracss custom-field value 'post-right' applied it, loop bring in

get_template_part( 'content' , 'right' ); 

if post has extracss custom-field value 'post-left' bring in

get_template_part( 'content' , 'left' ); 

this may not right way it, , i'm open other suggestions, thats overall idea. wanting 2 different post-templates 1 loop there numerous posts have either one, , want them brought in 1 after other.

as said it's either 1 or other template:

<?php  $extracss = get_post_meta( get_the_id(), 'extracss', true ); if ( $extracss == 'post-right' ) {     get_template_part( 'content' , 'right' );      } else {      get_template_part( 'content' , 'left' );    } ?> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -