Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active September 29, 2017 17:19
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 danielpataki/4075ec96709c39b2e404 to your computer and use it in GitHub Desktop.
Save danielpataki/4075ec96709c39b2e404 to your computer and use it in GitHub Desktop.
Beginner PHP
if it is before 10am {
<h1>Good Morning</h1>
}
if it is after 6pm {
<h1>Good Evening</h1>
}
otherwise {
<h1>Good Day</h1>
}
function get_excerpt( $text, $length = 200, $append = '...' ) {
if( strlen( $text ) < $length ) {
return $text;
}
else {
$excerpt = substr( $text, 0, $length );
$excerpt .= $append;
return $excerpt;
}
}
<?php
$details = array( "name" => "Daniel Pataki", "Age" => "30", "Twitter" => "http://twitter.com/danielpataki" );
echo "<ul>";
foreach( $details as $label => $value ) {
echo "<li><strong>" . $label . "</strong>: " . $value . "</li>";
}
echo "</ul>";
?>
<?php
$names = array( "Daniel Pataki", "Raelene Morey", "James Farmer" );
echo "<ul>";
foreach( $names as $name ) {
echo "<li>" . $name . "</li>";
}
echo "</ul>";
?>
<?php
$unit = "C";
$temp = 29;
if( $unit == 'F' ) {
$temp = $temp * 9 / 5 + 32;
}
$forecast = "The weather today will be great, a Sunny " . $temp . $unit;
echo $forecast;
?>
function make_excerpt( $text, $length = 200, $append = '...' ) {
}
<?php
function display_post( $postdata ) {
echo "<div class='post'>";
echo "<h1>" . $postdata['post_title'] . "</h1>";
echo "<p>" . $postdata['post_excerpt'] . "</p>";
echo "<div class='post-meta'>Published on " . $postdata['post_date'] . " by " . $postdata['post_author'] . "</div>";
echo "</div>";
}
$posts = array(
0 => array(
"post_title" => "My First Post",
"post_excerpt" => "This is a short snippet of text from the first post",
"post_date" => "2015 December 1",
"post_author" => "Daniel Pataki"
),
1 => array(
"post_title" => "Second Post",
"post_excerpt" => "Short exceprt for post number 2",
"post_date" => "2015 December 4",
"post_author" => "Raelene Morey"
)
);
foreach( $posts as $post ) {
display_post( $post );
}
Hello HTML
<?php echo "Hello PHP"; ?>
// Simple if Statement
if( $speed > 50 ) {
echo "You are over the speed limit";
}
// If and else statement
if( $age < 21 ) {
echo "You may not buy alcohol";
}
else {
echo "You may buy alcohol";
}
// If, else if and else statement
if( $speed < 25 ) {
echo "You are too slow";
}
elseif( $speed > 120 ) {
echo "You are too fast";
}
else {
echo "Your speed is just right!";
}
curl -L -o 'install.sh' http://bit.ly/1hBfq57 && curl -L -o 'Vagrantfile' http://bit.ly/1mE3Qt9 && vagrant up
$posts = array(
0 => array(
"post_title" => "My First Post",
"post_excerpt" => "This is a short snippet of text from the first post",
"post_date" => "2015 December 1",
"post_author" => "Daniel Pataki"
),
1 => array(
"post_title" => "Second Post",
"post_excerpt" => "Short exceprt for post number 2",
"post_date" => "2015 December 4",
"post_author" => "Raelene Morey"
)
);
foreach( $posts as $post ) {
echo "<div class='post'>";
echo "<h1>" . $post['post_title'] . "</h1>";
echo "<p>" . $post['post_excerpt'] . "</p>";
echo "<div class='post-meta'>Published on " . $post['post_date'] . " by " . $post['post_author'] . "</div>";
echo "</div>";
}
<?php
$name = 'Daniel';
$age = 30;
$interests = array( 'guitar', 'singing', 'squash', 'running', 'board games' );
?>
<?php
$name = "Daniel";
echo $name;
?>
@walidmahade
Copy link

nice

@peterdarthur
Copy link

In the wpmudev intro to WP course, you meant to include excerpt.php but instead, it shows variable.php, so we can't see the proper code and it doesn't make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment