conditional sidebar for certain post id Wordpress PHP
<p>I'm new to PHP and and using a Wordpress one-page theme where each section has a unique post ID.  I want to add a sidebar only to a post with a specific ID.  The code for that specific ID should add a few divs for styling as well as the sidebar.  I've tried adding a simple if/else statement and putting the code with the extra divs and sidebar in the <code>if</code>, and the original code without the sidebar or extra styling in the <code>else</code> but my code results not only styling for the widget on each post, but also removes the other content from the post I'm targeting.  This is the entire php file for the template.  Any help is much appreciated!</p>

<pre><code>&lt;?php
/*
Template Name: Onepage
*/
?&gt;
&lt;?php global $smof_data; ?&gt;
&lt;?php get_header();?&gt;
&lt;?php
if ( ( $locations = get_nav_menu_locations() ) &amp;&amp; $locations['primary'] &amp;&amp; !disable_onepage() ) {
  $menu = wp_get_nav_menu_object( $locations['primary'] );
  $menu_items = wp_get_nav_menu_items($menu-&gt;term_id);

  $pages_included = array();
  foreach ( $menu_items as $item ):
    if ($item-&gt;object != 'page') continue;
    $menu_state = get_post_meta($item-&gt;ID,'menu-item-menu-state',true);
    if ($menu_state == 'link') continue;
    $pages_included[] = $item-&gt;object_id;   
  endforeach;

} else {
  $pages_included[] = array();
} 

$count = 0;

/* IF THERE IS AT LEAST ONE PAGE MENU ITEM */
if (!empty($pages_included)) :

      $args = array(
        'post_type'     =&gt; 'page',
        'post__in'      =&gt; $pages_included,
        'posts_per_page'  =&gt; count($pages_included), 
        'orderby'       =&gt; 'post__in',
      );
    $onepage_query = new WP_Query();  
    $onepage_query-&gt;query($args);
endif;

    if ( $onepage_query-&gt;have_posts() ): while( $onepage_query-&gt;have_posts() ): $onepage_query-&gt;the_post(); $count++;?&gt;
    &lt;?php // Some PHP stuffs
    $page_template = get_post_meta(get_the_ID(),'_wp_page_template',true);
    $page_template = basename($page_template,'.php');

    /* -----------------------------    GET OPTIONS     ----------------------------------- */
    /* Title Options
    ----------------------------------------------- */
    $subtitle = get_post_meta(get_the_ID(),'_wi_subtitle',true);
    $subtitle = trim($subtitle);
    $title_image = false;
    $title_image_ids = get_post_meta(get_the_ID(),'_wi_title-image',false);
    $title_image_id = '';
    foreach ( $title_image_ids as $tii ) {
      if ( !wp_get_attachment_image_src( $tii ) ) continue;
      $title_image_id = $tii;
    }

    if ( $title_image_id ) {
      $title_image = wp_get_attachment_image_src($title_image_id,'full');
      $title_image = $title_image[0];
      }
    $hide_title = get_post_meta(get_the_ID(),'_wi_hide-title-area',true);

    /* Page Background Options
    ----------------------------------------------- */
    $page_background_type = get_post_meta(get_the_ID(),'_wi_page-background-type',true);
    $page_background_color = get_post_meta(get_the_ID(),'_wi_page-background-color',true);
    $page_background_image = get_post_meta(get_the_ID(),'_wi_page-background-image',true);
    $page_background_image_size = get_post_meta(get_the_ID(),'_wi_page-background-image-size',true);
    $page_background_image_position = get_post_meta(get_the_ID(),'_wi_page-background-image-position',true);
    $page_background_pattern = get_post_meta(get_the_ID(),'_wi_page-background-pattern',true);
    $page_background_pattern_retina = get_post_meta(get_the_ID(),'_wi_page-background-pattern-retina',true);

    /* Separator Background Options
    ----------------------------------------------- */
    $disable_separator = get_post_meta(get_the_ID(),'_wi_disable-page-separator',true);
    $separator_content = get_post_meta(get_the_ID(),'_wi_separator-content',true);
    $background_or_pattern = get_post_meta(get_the_ID(),'_wi_background-image-or-pattern',true);
    if ( $background_or_pattern!='pattern' ) $background_or_pattern = 'background';
    $background_images = get_post_meta(get_the_ID(),'_wi_background-image',false);
    $background_image = '';
    foreach ( $background_images as $bgim ) {
      if ( !wp_get_attachment_image_src( $bgim) ) continue;
      $background_image = $bgim;
    }   

    $overlay_opacity = get_post_meta(get_the_ID(),'_wi_overlay-opacity',true);
    $overlay_opacity = absint($overlay_opacity);
    $clipmask_opacity = get_post_meta(get_the_ID(),'_wi_clipmask-opacity',true);
    $clipmask_opacity = absint($clipmask_opacity);
    $enable_parallax = get_post_meta(get_the_ID(),'_wi_enable-parallax-effect',true);
    $parallax_class = ( $enable_parallax ) ? ' parallax' : '';

    $padding = get_post_meta(get_the_ID(),'_wi_padding-top-bottom',true);   

    $predefined_pattern = get_post_meta(get_the_ID(),'_wi_predefined-pattern',true);
    $retina_custom_patterns = get_post_meta(get_the_ID(),'_wi_retina-custom-pattern',false);
    $retina_custom_pattern = '';
    foreach ($retina_custom_patterns as $bgim ) {
      if ( !wp_get_attachment_image_src( $bgim) ) continue;
      $retina_custom_pattern = $bgim;
    }   

    $custom_patterns = get_post_meta(get_the_ID(),'_wi_custom-pattern',false);
    $custom_pattern = '';
    foreach ( $custom_patterns as $bgim ) {
      if ( !wp_get_attachment_image_src( $bgim) ) continue;
      $custom_pattern = $bgim;
    }

    if ( $background_or_pattern != 'pattern' ) {
          $background_type = 'image';
          if ( $background_image ) {
            $background_image = wp_get_attachment_image_src($background_image,'full');
            $background_image = $background_image[0];
            $background_size = 'cover';           
          } else {
            $background_image = '';
            $background_size = '';
          }
          $retina_background_image = $background_image;

    } else {  //  $background_or_pattern == 'pattern'
          $background_type = 'pattern';
          if ( $custom_pattern ) {
            $pattern = $custom_pattern;
            if ( $retina_custom_pattern ) {
              $retina_pattern = $retina_custom_pattern;
            } else {
              $retina_pattern = $custom_pattern; 
            }
            $pattern = wp_get_attachment_image_src($pattern,'full');
            $pattern = $pattern[0];
            $retina_pattern = wp_get_attachment_image_src($retina_pattern,'full');
            $retina_pattern = $retina_pattern[0];     
          } else {
            $pattern = $predefined_pattern;
            $retina_pattern = str_replace( '.png' , '_@2X.png' , $pattern );
          }

          if ( !$pattern ) $pattern = get_template_directory_uri().'/images/sidrbg/argyle.png';

          if ( $pattern ) {
            $background_image = $pattern;
            $background_size = (array) @getimagesize($pattern);
            if ( isset($background_size[0]) &amp;&amp; isset($background_size[1]) ) {
              $background_size = $background_size[0] . 'px ' . $background_size[1] . 'px';
              } else {
              $background_size = 'auto';
              }
          } else {
            $background_image = '';
            $background_size = '';
          }

          if ( $retina_pattern ) {
            $retina_background_image = $retina_pattern;
          } else {
            $retina_background_image = $pattern;
          }

    } // image or pattern     
  ?&gt;
  &lt;?php if ( !$disable_separator ) :?&gt;
  &lt;style type="text/css"&gt;
    #page-separator-&lt;?php echo esc_html($post-&gt;post_name);?&gt; {
      background-image:url(&lt;?php echo esc_url($background_image);?&gt;);
      -webkit-background-size:&lt;?php echo esc_html($background_size);?&gt;;
      -moz-background-size:&lt;?php echo esc_html($background_size);?&gt;;
      background-size:&lt;?php echo esc_html($background_size);?&gt;;
      padding-top:&lt;?php echo absint($padding);?&gt;px;
      padding-bottom:&lt;?php echo absint($padding);?&gt;px;
    }
    #page-separator-&lt;?php echo esc_html($post-&gt;post_name);?&gt; .overlay {
      opacity:&lt;?php echo ($overlay_opacity/100);?&gt;;
      -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=&lt;?php echo ($overlay_opacity);?&gt;)";
      filter: alpha(opacity=&lt;?php echo ($overlay_opacity);?&gt;);
      }
    #page-separator-&lt;?php echo esc_html($post-&gt;post_name);?&gt; .clipmask {
      opacity:&lt;?php echo ($clipmask_opacity/100);?&gt;;
      -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=&lt;?php echo ($clipmask_opacity);?&gt;)";
      filter: alpha(opacity=&lt;?php echo ($clipmask_opacity);?&gt;);
      }
    @media (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi){
      #page-separator-&lt;?php echo esc_html($post-&gt;post_name);?&gt; {
        background-image:url(&lt;?php echo esc_url($retina_background_image);?&gt;);
        }
    }         
  &lt;/style&gt;
  &lt;div class="&lt;?php echo esc_attr('page-separator background-type-' . $background_type . $parallax_class);?&gt;" id="&lt;?php echo esc_attr('page-separator-' . $post-&gt;post_name);?&gt;"&gt;
    &lt;div class="overlay"&gt;&lt;/div&gt;
    &lt;div class="clipmask"&gt;&lt;/div&gt;
    &lt;div class="container"&gt;
      &lt;div class="content"&gt;
        &lt;?php echo do_shortcode($separator_content); ?&gt;
      &lt;/div&gt;&lt;!-- .content --&gt;
    &lt;/div&gt;&lt;!-- .container --&gt; 
  &lt;/div&gt;&lt;!-- .page-separator #page-separator-$post-&gt;post_name --&gt;

  &lt;?php endif; // enable/disable page separator ?&gt;

  &lt;style type="text/css"&gt;

    &lt;?php if($page_background_color){?&gt;
      .wi-page#&lt;?php echo esc_html($post-&gt;post_name);?&gt; {
        background-color:&lt;?php echo sanitize_hex_color($page_background_color);?&gt;;
        }
    &lt;?php } ?&gt;

/* --------- BACKGROUND PATTERN OPTIONS ------------ */
&lt;?php if ($page_background_type == 'pattern'): ?&gt;

    &lt;?php if($page_background_pattern){
        $pattern = wp_get_attachment_image_src($page_background_pattern,'full');
        $pattern = $pattern[0];
        $background_size = (array) @getimagesize($pattern);
        $background_size = $background_size[0] . 'px ' . $background_size[1] . 'px';
    ?&gt;
      .wi-page#&lt;?php echo esc_html($post-&gt;post_name);?&gt; {
        background-image:url(&lt;?php echo esc_url($pattern);?&gt;);
        -webkit-background-size:&lt;?php echo esc_html($background_size);?&gt;;
        -moz-background-size:&lt;?php echo esc_html($background_size);?&gt;;
        background-size:&lt;?php echo esc_html($background_size);?&gt;;
        }
    &lt;?php } ?&gt;

    &lt;?php if($page_background_pattern_retina){
        $pattern = wp_get_attachment_image_src($page_background_pattern_retina,'full');
        $pattern = $pattern[0];
    ?&gt;
    @media (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi){
      .wi-page#&lt;?php echo esc_html($post-&gt;post_name);?&gt; {
        background-image:url(&lt;?php echo esc_url($pattern);?&gt;);
        }
      } 
    &lt;?php } ?&gt;

/* --------- BACKGROUND IMAGE OPTIONS ------------ */
&lt;?php elseif ($page_background_type == 'image'): ?&gt;

    &lt;?php if($page_background_image){
      $page_background_image = wp_get_attachment_image_src($page_background_image,'full');
      $page_background_image = $page_background_image[0];
    ?&gt;
      .wi-page#&lt;?php echo esc_html($post-&gt;post_name);?&gt; {
        background-image:url(&lt;?php echo esc_url($page_background_image);?&gt;);
        -webkit-background-size:&lt;?php echo esc_html($page_background_image_size);?&gt;;
        -moz-background-size:&lt;?php echo esc_html($page_background_image_size);?&gt;;
        background-size:&lt;?php echo esc_html($page_background_image_size);?&gt;;
        background-position:&lt;?php echo esc_html($page_background_image_position);?&gt;;
        }
    &lt;?php } ?&gt;

&lt;?php endif; // page background type ?&gt;

  &lt;/style&gt;

      &lt;?php
  if ($post-&gt;ID == '4048') {
    ?&gt;
  &lt;div &lt;?php post_class('wi-page '.$page_template);?&gt; id="&lt;?php echo esc_attr($post-&gt;post_name);?&gt;"&gt;
  &lt;?php if ( !$hide_title ){ ?&gt;  
    &lt;!--      TITLE       --&gt;
    &lt;div class="title-area"&gt;
      &lt;div class="container"&gt;
        &lt;div class="pad"&gt;
          &lt;?php if ( $title_image ) : ?&gt;
          &lt;div class="image"&gt;
            &lt;img src="&lt;?php echo esc_url($title_image);?&gt;" alt="&lt;?php the_title();?&gt;" /&gt;
          &lt;/div&gt;&lt;!-- .image --&gt;
          &lt;?php endif; // header_image ?&gt;
          &lt;h2 class="title"&gt;&lt;?php the_title();?&gt;&lt;/h2&gt;
          &lt;?php if ($subtitle):?&gt;
          &lt;h3 class="subtitle"&gt;&lt;?php echo wp_kses($subtitle,''); ?&gt;&lt;/h3&gt;
          &lt;?php endif;?&gt;
        &lt;/div&gt;&lt;!-- .pad --&gt; 
      &lt;/div&gt;&lt;!-- .container --&gt; 
    &lt;/div&gt;&lt;!-- .title-area --&gt;
  &lt;?php }
  }else{ ?&gt;  
    &lt;div class="content-area"&gt;
      &lt;div class="container"&gt;
        &lt;div class="row-fluid"&gt;  &lt;!-- added for styling --&gt;
          &lt;div id="primary" class="span8"&gt;   &lt;!-- added for styling --&gt;
            &lt;?php the_content();?&gt;
          &lt;/div&gt; &lt;!-- added for styling #primary --&gt;
        &lt;?php get_sidebar('video-sidebar');?&gt;
        &lt;/div&gt;&lt;!-- .row-fluid --&gt;
      &lt;/div&gt;&lt;!-- .container --&gt;

      &lt;div class="clearfix"&gt;&lt;/div&gt;
    &lt;/div&gt; &lt;!-- content-area --&gt;
&lt;/div&gt;&lt;!-- .wi-page --&gt;
&lt;?php } ?&gt; 

  &lt;?php
  endwhile; // have posts 
endif; // have posts

if (!empty($pages_included)) :  

  wp_reset_query();

endif;

// in case onepage disabled but user wants to use onepage template for some usage
if ( disable_onepage() ):

  if (have_posts()) :?&gt;
    &lt;div class="container"&gt;
    &lt;?php while(have_posts()): the_post(); ?&gt; 
      &lt;article &lt;?php post_class('article wi-single');?&gt; id="post-&lt;?php the_ID();?&gt;"&gt;

        &lt;?php the_content();?&gt;
        &lt;?php wp_link_pages( array( 'before' =&gt; '&lt;div class="page-links-container"&gt;&lt;div class="page-links"&gt;&lt;div class="page-links-label"&gt;' . __( 'Pages:', 'wi' ) . '&lt;/div&gt;', 'after' =&gt; '&lt;/div&gt;&lt;/div&gt;', 'pagelink' =&gt; '&lt;span&gt;%&lt;/span&gt;' ) ); ?&gt;

      &lt;/article&gt;&lt;!-- .article --&gt; 
    &lt;?php endwhile;?&gt;
    &lt;/div&gt;&lt;!-- .container --&gt; 
  &lt;?php endif;
endif; // if disable onepage

?&gt;
&lt;?php get_footer();?&gt;
</code></pre>