Skip to content

Instantly share code, notes, and snippets.

@colegeissinger
Last active December 21, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colegeissinger/6363248 to your computer and use it in GitHub Desktop.
Save colegeissinger/6363248 to your computer and use it in GitHub Desktop.
An example of a small PHP script for a presentation I gave on August 28th, 2013 for WIMP (Web and Interactive Media Professionals) http://www.meetup.com/beawimp/events/130142102/
<?php
// Setup some static variables for us to use
$title = 'Our Simple PHP Page'; // We'll create a string for the title tag of the page
$year = 2013; // We'll also create a variable that will contain the year which is used in the footer
// We'll also create an array that holds multiple author information
// If we leave the array key's blank, that makes this an "indexed" array.
// Each key-pair will work on a base of 0 and count up (E.G. 0 => 'value', 1 => 'value 2')
$authors = array(
'Author 1',
'Author 2'
);
// Create a variable to be used in ourconditional statement.
// We'll use this variable to test it's value in the comments area of each article and output different information.
// For this demo, we'll create two booleans, that will allow us to see if comments are 'enabled'.
// Article 1 will have comments enabled, while Article 2 will be disabled.
$comment1 = true;
$comment2 = false;
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $title; ?></title>
</head>
<body>
<header>
<nav>
<ul>
<li>Your menu</li>
</ul>
</nav>
</header>
<section>
<article>
<header>
<h2>Article title</h2>
<p>Posted on <time datetime="2013-08-028T16:31:24+02:00">August 28th 2013</time>
by <a href="#"><?php echo $authors[0]; ?></a> -
<?php
// This conditional would return true and output the HTML comment link.
// If it was false, it would then return the string after the else statement.
if ( $comment1 ) {
echo '<a href="#comments">6 comments</a>';
} else {
echo 'Comments Disabled';
}
?>
</p>
</header>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</article>
<article>
<header>
<h2>Article title</h2>
<p>Posted on <time datetime="2013-08-028T16:31:24+02:00">August 28th 2013</time>
by <a href="#"><?php echo $authors[1]; ?></a> -
<?php
// This conditional will return false and output the string saying comments are disabled.
// If it was true, it would then return the HTML comment link.
if ( $comment2 ) {
echo '<a href="#comments">6 comments</a>';
} else {
echo 'Comments Disabled';
}
?>
</p>
</header>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</article>
</section>
<aside>
<h2>About section</h2>
<p>Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</aside>
<footer>
<p>Copyright <?php echo $year; ?> Your name</p>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment