skip to Main Content

Can anyone please help me wrap the condition inside another condition in php.

I have this code #1 that I want to be inside code #2.

Here’s code #1

<?php if( get_field('highlights') ): ?>
    <div class="overview">
    <h3>Quick Overview</h3>
    <?php the_field('highlights'); ?>
    </div>
<?php endif; ?>

Here’s code #2

<?php if(strstr($_SERVER['HTTP_REFERER'],'www.example.com')) 
{
  echo '**CODE #1 should be placed here**';
}
?>

Sorry, I don’t haev any knowledge in PHP.

Wrapping code 1 inside code 2

2

Answers


  1. Chosen as BEST ANSWER

    After several trial and error, here's what I have to make it work. Please correct me if there's something wrong or to improve.

    <?php if (strstr($_SERVER['HTTP_REFERER'], 'www.google.com')){ ?>
          
        <?php if( get_field('highlights') ):?>
          <div class="overview">
          <h3>Quick Overview</h3>
          <?php the_field('highlights'); ?>
        </div>
    <?php endif; ?>
    <?php } ?>
    

  2. This should work in theory. Though I’m unsure what the highlights field is for.

    <?php 
    if(strstr($_SERVER['HTTP_REFERER'],'www.example.com')){
      if( get_field('highlights') ){ ?>
        <div class="overview">
        <h3>Quick Overview</h3>
        <?php the_field('highlights'); ?>
        </div>
        <?php 
      }
    }
    ?>
    

    You may want to replace <?php the_field('highlights'); ?> with something like <?=highlight ?> and iterate through the highlights in a loop. That depends on the situation though.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search