displaying content when a condition is met

« Go back

If Condition Is Met, Show Content

PHP
<?php
// Checks to see if the URL contains the text string 
// and if it does, it writes the HTML code to the page
if( stristr($_SERVER['PHP_SELF'], '/foo/bar/1/') == TRUE )
<?php { ?>
<!--Your HTML Content Goes Here-->
<?php } ?>

Show content only when a condition is met. This can be teamed up with other conditions to include one sidebar.php file with all of your secondary navigation, and then show the proper navigation on a certain page. The code above also makes it easier to add HTML between PHP without the need for echo ' '

Source: http://php.net/manual/en/control-structures.elseif.php

Share and Enjoy:
  • Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg

Tags:

About the author

Author

I started my career as a print designer and wanted nothing to do with "code". Then slowly I began to learn by reading tutorials online. My learning process has been challenging, yet very rewarding. My goal is to document the lessons I have learned and to encourage other beginners in the field of web design / front-end programming. - Jacob Lett