This file contains individual source code blocks that, together, build a WordPress Theme.
This is a literate programming document, which basically means that it is a written document with a computer program nested in its body. The code snippets are extracted from this document and “tangled” together to build the final program.
If you accidentally delete all of your theme files, or want to reproduce them on another workstation or WordPress site, all you need is the README file, and you can rebuild the theme.
In order to proceed with this project you will only need:
- Install Emacs (if you haven’t already)
- Open README.org file
- Type key command
C-c C-v C-t
to initiate theorg-babel-tangle
function
(In Emacs, the “C” represent the control key on your keyboard.)
The “freerun” theme consists of four files:
Every WordPress themes starts with the style.css
file, containing
the theme information:
/*
Theme Name: freerun
Author: Chris M
Version: 1.0
*/
body {
margin-left: 8%;
margin-right: 8%;
}
/*
#headerimg h1 {
font-family: fantasy;
}
#headerimg a {
text-decoration: none;
color: black;
}
#headerimg a:hover {
text-decoration: none;
color: #14cc17;
}
.description {
margin-top: -20px;
}
*/
The index.php
file uses the WordPress “loop” to cycle through
published posts.
<?php
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h2>• <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
The single.php
template generates content for a single post.
<?php
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
(<?php the_date(); ?>)
<?php the_content(); ?>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
The page.php
file generates the content for a single page.
This page template includes some special code to generate a list of “child” pages (if there are any). WordPress pages are “hierarchical,” which means you can nest pages underneath other pages.
<?php
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<!--List child pages (if there are any)-->
<?php
$children = wp_list_pages( 'title_li=&child_of='.$post->ID.'&echo=0' );
if ( $children) : ?>
<ul>
<?php echo $children; ?>
</ul>
<?php endif; ?>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
For demonstration purposes, this following code block allows for shell commands. No tangle argument here, any shell commands that you run from here will not affect the theme files. However, a “results” argument with parameter “raw” will echo the raw output in the buffer.
Add PHPUnit to your project using Composer (may take a minute or so):
/usr/local/bin/composer require --dev phpunit/phpunit ^9
Get the version:
./vendor/bin/phpunit --version