Skip to content

Instantly share code, notes, and snippets.

@johnmorris
johnmorris / datetime.php
Created November 20, 2015 00:01
How to Use the PHP DateTime Class Instead of the PHP Date Function
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Manipulating PHP DateTime</title>
</head>
<body>
<h1>Working With DateTime Extension (PHP 5.2+)</h1>
<h4>Defaults to the time now and is an object:</h4>
<?php $date = new DateTime(); print_r($date); ?><br>
@johnmorris
johnmorris / awesomeadmin.php
Last active November 13, 2015 22:16
How to Create a Custom WordPress Admin and Login Theme
<?php
/*
Plugin Name: Awesome Admin
Plugin URI: https://www.youtube.com/watch?v=ofPWdC9U7A&list=PLrG78JjvL7hXpxdunxZSb037-ZpYBdxw6
Description: Dummy plugin for tutorial on creating a custom admin theme
Author: John Morris
Version: 1.0
Author URI: http://johnmorrisonline.com
*/
@johnmorris
johnmorris / .htaccess
Last active December 7, 2020 03:58
Create a custom 404 page not found error page
<Files .htaccess>
order allow,deny
deny from all
</Files>
ErrorDocument 403 /errors/error.php
ErrorDocument 404 /errors/error.php
ErrorDocument 405 /errors/error.php
ErrorDocument 408 /errors/error.php
ErrorDocument 500 /errors/error.php
@johnmorris
johnmorris / sendmail.php
Created October 28, 2015 16:54
How to send email with PHP
<?php
// Recipient
$to = 'RECIPIENT EMAIL ADDRESS';
// Subject
$subject = 'This is our test email';
// Message
$message = '<h1>Hi there.</h1><p>Thanks for testing!</p>';
@johnmorris
johnmorris / parsexml.php
Last active October 22, 2015 15:31
How to parse XML using SimpleXML and PHP (Tutorial: http://www.johnmorrisonline.com/how-to-parse-xml-with-simplexml-and-php/)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>How to Parse XML With SimpleXML and PHP</title>
</head>
<body>
<?php
$url = 'http://www.johnmorrisonline.com/feed/';
$xml = simplexml_load_file($url) or die("Can't connect to URL");
@johnmorris
johnmorris / oddeven.php
Created October 14, 2015 20:39
Zebra striped table in a loop with odd even classes using PHP
<?php
function oddeven($count, $increment = 2) {
$state = $count%$increment;
if ( ! $state ) {
return 'even';
}
return 'odd';
}
@johnmorris
johnmorris / about.php
Created September 20, 2015 18:05
Add active class to navigation menu item based on URL using jQuery
<!DOCTYPE html>
<html>
<head>
<title>jQuery Active Class</title>
<link href="style.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<nav>
@johnmorris
johnmorris / index.html
Created September 11, 2015 18:27
Set DIV height to 100% of parent using jQuery
<!DOCTYPE html>
<html>
<head>
<title>jQuery DIV 100% Height of Container</title>
<style>
.container {
overflow: hidden;
border: 1px solid red;
}
@johnmorris
johnmorris / accordion.php
Created September 6, 2015 13:16
A simple jQuery accordion (video tutorial at: http://youtu.be/6LfMsU1LfM8)
<!DOCTYPE html>
<html>
<head>
<title>jQuery Accordion</title>
<style>
html, body {
font-size: 100%;
}
.accordion {
@johnmorris
johnmorris / nav.html
Created August 8, 2015 14:22
Build a responsive menu with HTML, CSS and jQuery (full tutorial here: http://youtu.be/h30qPvATvEA)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Responsive Navigation</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<style>
body {
margin: 0;