最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Background Image Does Not Display on Page

programmeradmin0浏览0评论

So I did what you said to correct the code and it fixed my site but I see that the pages that use this layout do not have the background images showing. I have included the whole code for the section called Basic Content to see if you see any other issues for what may be causing this. Thanks for your help!

//Basic Content elseif( get_row_layout() == 'basic_content' ):

  $bgimage      = get_sub_field('background_image');
  $bgcolor      = get_sub_field('background_color');
  $maincontent  = get_sub_field('main_content');
  $sectionid    = get_sub_field('id');
  $newsize      = get_sub_field('new_size');
  $textalign    = get_sub_field('text_alignment');
  
            
  $bg = (!$bgimage == '') ? 'style="background-image:url("'.$bgimage['url'].'")' : '';

  
  if($textalign == 'Left'){ $ta = 'text-left'; } else { $ta = ''; }
  
  
  echo  '<div id="'.$sectionid.'" class="row basic '.$newsize.' '.$bgcolor.' '.$ta.'" '.$bg.'>';
    
    if($newsize == 'full'){
      
      echo $maincontent;
    
    } elseif($newsize == 'medium') {
      
        echo '<div class="container">' .
          
            $maincontent .
            
          '</div>';
      
    } elseif($newsize == 'small') {
      
        echo '<div class="small-container">' .
          
            $maincontent .
            
          '</div>';
          
    } else {
      
      echo '<div class="small-container">' .
          
            $maincontent .
            
          '</div>';
          
    }
  
  echo '</div>';

So I did what you said to correct the code and it fixed my site but I see that the pages that use this layout do not have the background images showing. I have included the whole code for the section called Basic Content to see if you see any other issues for what may be causing this. Thanks for your help!

//Basic Content elseif( get_row_layout() == 'basic_content' ):

  $bgimage      = get_sub_field('background_image');
  $bgcolor      = get_sub_field('background_color');
  $maincontent  = get_sub_field('main_content');
  $sectionid    = get_sub_field('id');
  $newsize      = get_sub_field('new_size');
  $textalign    = get_sub_field('text_alignment');
  
            
  $bg = (!$bgimage == '') ? 'style="background-image:url("'.$bgimage['url'].'")' : '';

  
  if($textalign == 'Left'){ $ta = 'text-left'; } else { $ta = ''; }
  
  
  echo  '<div id="'.$sectionid.'" class="row basic '.$newsize.' '.$bgcolor.' '.$ta.'" '.$bg.'>';
    
    if($newsize == 'full'){
      
      echo $maincontent;
    
    } elseif($newsize == 'medium') {
      
        echo '<div class="container">' .
          
            $maincontent .
            
          '</div>';
      
    } elseif($newsize == 'small') {
      
        echo '<div class="small-container">' .
          
            $maincontent .
            
          '</div>';
          
    } else {
      
      echo '<div class="small-container">' .
          
            $maincontent .
            
          '</div>';
          
    }
  
  echo '</div>';
Share Improve this question asked Feb 14, 2022 at 21:09 Steve BonillaSteve Bonilla 1
Add a comment  | 

1 Answer 1

Reset to default 0

Based on what's provided I would suggest doing some var_dump tests on the $bg variable, it would seem that the ternary logic there is equating to false and thus nothing is being assigned to the $bg variable.

Do you have a default background image, if the $bgimage field is not set by a user?

Also, be sure to check the spelling of what you set up in ACF field names, I've had situations like this where ACF content wasn't showing up and the issue was a rogue space in the field name or a misspelled field name.

发布评论

评论列表(0)

  1. 暂无评论