WordPress.org

Forums

if time=x echo --- including div's with ids inside echo function (2 posts)

  1. gcoulby
    Member
    Posted 2 years ago #

    OK heres the code.

    <?php
    
    $c_time = mktime();
    $open = strtotime('Today 5pm');
    $close = strtotime('Today 7pm');
    
    if ($c_time > $open && $c_time < $close) {
        echo ' THIS IS WHERE I WANT TO ADD DIVs';
    }
         else {
             echo 'DISPLAY THIS CODE.';
    }
    
    		?>

    That's the working piece of code I have which basically states that if the time is between 5 and 7pm display the first set of code, if not display what is in the Else tags.... that bits easy and works.

    however, i want to include the following piece of php/html inside the echo tags I've read somewhere that you need to replace ' with \' but haven't been able to implement it.

    <div id="animated-head-link"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="Return to <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>' Homepage." rel="home">
    
    			<div id="sky">
    
    				<div id="logo">			</div><!-- END LOGO -->
    
    				<div id="clouds">		</div><!-- END CLOUDS -->
    
    				<div id="mountains">	</div><!-- END MOUNTAINS -->
    
    			</div><!-- END SKY -->
    
    </a> </div><!-- END ANIMATED-HEAD-LINK -->

    This piece of code also works fine on it's own but doesn't work when echoed.

    I HOPE THIS MAKES SENSE.

  2. gcoulby
    Member
    Posted 2 years ago #

    stackflow solved it

    <?php
    
    $c_time = mktime();
    $open = strtotime('Today 5pm');
    $close = strtotime('Today 7pm');
    ?>
    
    <?php if ($c_time > $open && $c_time < $close): ?> 
    
      <div id="animated-head-link">
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="Return to  <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>' Homepage." rel="home">
    
            <div id="sky">
    
                <div id="logo">         </div><!-- END LOGO -->
    
                <div id="clouds">       </div><!-- END CLOUDS -->
    
                <div id="mountains">    </div><!-- END MOUNTAINS -->
    
            </div><!-- END SKY -->
    
        </a>
      </div><!-- END ANIMATED-HEAD-LINK -->
    
    <?php else: ?>
      DISPLAY THIS CODE.
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic