0

I am building a custom page with repeatable metaboxes that controls content, images and background image. I am having issues when it comes to displaying the background image as an inline style. As of right now I am using the below code to generate my image (which works).

 <?php global $post; $entries = get_post_meta( get_the_ID(), 'project_pages', true ); foreach ( $entries as $key => $entry ) {?>
       <section class="section" style:background=background:url("<?php echo $entries [$key]['page_background'];?>)">
        <div class="body-wrapper">
            <article class="pro-content-half up">
             <h4><?php echo $entries [$key]['header'];?></h4>
             <?php echo wpautop( $entries [$key]['page-content'] ); ?>
             </article>
             <article class="pro-image-half faderight">
                <img src="<?php echo $entries [$key]['page_image'];?>" />
            </article>
         </div><!-- BODY WRAPPER -->
 </section>
 <?php } //endforeach ?> 

Not every div that is controlled by the repeatable metabox will have a background inline style, so when left blank I get . I would like to echo, if it is possible, the background image to only show when the metabox is active and when left empty the div should look like this

This is what I have tried with no success.

 <?php echo'style="background:url('.$entries [$key]["$page_background"]')"' ?>

Any help would be great.

  • How are you checking to see if the metabox is active and what are you applying the style to when it's not? – jgraup Dec 29 '15 at 18:25
  • the metabox is active through get_post_meta and it works when the style is set up in my first example. As for applying the style i would like it to be hidden when the met box is not active. @jgraup – user3756781 Dec 29 '15 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.