Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Learn to Create WordPress Themes by Building 5 Projects
Learn to Create WordPress Themes by Building 5 Projects

Learn to Create WordPress Themes by Building 5 Projects: Master the fundamentals of WordPress theme development and create attractive WordPress themes from scratch

Arrow left icon
Profile Icon Eduonix Learning Solutions
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (5 Ratings)
Paperback Dec 2017 458 pages 1st Edition
eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Eduonix Learning Solutions
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (5 Ratings)
Paperback Dec 2017 458 pages 1st Edition
eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learn to Create WordPress Themes by Building 5 Projects

Building a WordPress Theme

In this chapter, we'll jump into more details and get our feet wet. In the previous chapter, we covered the basics, but now we'll use some of the more advanced concepts to build a WordPress theme. Here we will cover the following concepts:

  • Custom template pages
  • Archived pages
  • Post formats
  • Custom home pages

Let's take a quick look at the project:

In the preceding image, you can see the WordpressDev home page with some widgets that we'll implement, such as the showcase. You can also see three box widgets.

Post formats

When you visit the blog page, you can see we have multiple post types:

  • Gallery posts
  • Linked posts
  • A-side posts
  • Regular blog posts

In the following screenshot, you can see Gallery post and the linked posts:

This is how the A-side post looks:

This is what a regular blog post looks like:

When we click on Read More, it takes us to a single page where we have our comment form and the customized comments interface, as shown in the following image:

We will now see how to create custom layouts; for instance, the About page, shown in the following screenshot, is in a layout called Company, where we have the phone number displayed in a div class:

Now let's click on Posts or Pages and then on About:

You'll see that we have Default Template and Company Layout in the Template option:

Now we will see how to create a submenu for pages that have parents; for instance...

Creating a design using HTML and CSS

Let's see how to create our theme, but before we get into WordPress, we'll first map out and just create the design using HTML and CSS.

Usually, when we build a WordPress theme, or a Drupal or Joomla theme, you can usually create the design first using just static HTML and CSS.

Building the HTML body

As you can see in the following screenshot, we have an empty folder called advanced-wp-html, and we'll create a couple of files here. First, we'll create an index.html file, and then we'll create our style sheet, which will just be style.css.

Let's open both the files with Sublime editor. In the index.html file, add in our core html markup, as shown in the following...

Creating a WordPress theme

Now we'll convert our HTML template into a WordPress theme. I have a fresh install of WordPress here with just the default twentysixteen theme. We will go to the WordPress folder, wp-content and then in the themes folder, we will create a new folder and name it advanced-wp.

Here we will create a style.css file and also an index.php file.

Now let's open the style sheet. Here we will put our declaration first, so that WordPress can see the theme. We will set Theme Name as Advanced WP and enter a value for Author. Next we will add Author URI, a description, and a version:

/*
Theme Name: Advanced WP
Author: Brad Traversy
Author URI: http://eduonix.com
Description: Advanced Wordpress Theme
Version: 1.0
*/

Now we do have a screenshot as well in our project files, so we will add that.

Let's go to C:. Since I'm using AMPPS,...

Displaying blog post

We created the theme and added the header and navigation bar. All of this stuff on the page is now dynamic and integrated with WordPress, but this is all just static HTML.

Let's go back to our index.php page and go down to where we have the container content div, and we have different blog posts. We have three article tags with blog posts; we will delete two out of the three.

Then we will cut the paragraphs down and make it much shorter just so we can get it all in the page or in view. We want to write in this main block div, and we want to create our post loop.

First, we'll have to check for posts, and for that, we will enter if(have_posts),and then we have to end it after the ending </article> tag. We will put an else statement as well. If there are no posts, then we will enter php echo, with the wpautop() function, where we can put the text...

Creating a single post and adding an image

We will now see how to create a single post. If we click on Read More now, it takes us to the single post, but it's not what we want, we want to change this. Also, we want the ability to add a featured image to a post, also called a thumbnail. Let's start with the thumbnail. We'll first go to functions.php and we need to enable that support for our theme. For this, we'll go to the adv_theme_support() function and add a Featured Image Support comment. Next, we'll enter the add_theme_support() function and pass in post-thumbnails, as shown here:

// Theme Support
function adv_theme_support(){
// Featured Image Support
add_theme_support('post-thumbnails');

Let's save this, and if we go to, let's say Blog Post One, you'll see that we have the Featured Image block:

We will click on Set...

Creating custom archive pages

Let's create custom archive pages. Now if we click on one of the categories, it'll take us to a category archive.

If we click on admin, the username, it will take us to the author archive. There are others as well. We can also have archives by dates, we can have them by tags, and so on. So let's go into our themes folder. We will create a new file and save that as archive.php and open that up.

Now if we go back and click on a category, you can see it's blank because it's looking at the archive.php page. We will copy what's in the index.php page and paste that in archive.php.

I want these pages to be much more simple. We don't need the meta, and we don't need the image; pretty much just the title and the date is all that we want. So let's go to where we have the <article> tag and get rid of the whole...

Different post formats

Let's take a look at a few different things now. We'll look at post types or post formats. Right now, if we look at our theme, we have just basically one kind of post, and it's just a standard blog post. We can also have things, such as galleries, links, images, and quotes status updates, and we can format these different types of posts in different ways. We will now see how to do that, how to add these to our theme. Also, we'll look at a function called get_ template_part(), which allows us to stop repeating ourselves. For instance, if we look at our index page, we have while (have_posts()), and then we're just outputting our post. We observe the same thing in the archive, in search.php, and so on. So we want something that's going to stop us from repeating ourselves over and over. I know that each of these files have minor...

Pages, custom templates, and sub navigation

Now we'll move from the posts to pages. If we visit the About page, you can see that it's formatted just like a post, which is definitely not what we want.

We just want the pages to have the title, we don't want metadata, Read More, and stuff like that. So to change all that, we have to create a new file and save it as page.php.

Now if I go back to that page and reload, it's just a blank white page. It's looking to this file to parse it.

Just to start with, I'll grab what we have in the index page, paste it in page.php, and just change some stuff. We want the while loop, we'll not use get_template_part(), so we can get rid of that. We want an <article> tag, and let's give this a class of page. Let's also put in an <h2> tag. This is where the title will go, so we'll say &lt...

Working with Theme Widgets

In this section, we'll take a look at widgets.

Right now, we have a sidebar, but this is just static content in our php file. So we want this to come from the widget system. Also, we should be able to add multiple widgets in the sidebar. Now, on the blog page, and on any other page, this is going to be the only widget aside from a custom Home page that we'll create later on. However, we will add those positions in our functions file.

So, let's open up functions.php, and go right under the after_theme_setup action; this will be to set up widget locations. We'll create a function, call it init_widgets() and it will take an id; then, we'll say register_sidebar. Now, even though this is called register_sidebar, this is used with all widget positions, not just a sidebar. It takes in an array and it's going to take a name; this...

Custom home page

Now we'll create a custom home page and then add widgets to the positions that we added.

Let's create a new file and save this as front-page.php. If we reload the home page it goes completely blank because it's looking at front-page.php file. So I'll copy what we have in page.php and paste it in front-page.php.

Now let's reload:

This doesn't look very good because we're showing the posts with just the page formatting. So let's go into pages, and create two new pages. We will call one Home; we'll just say This is the homepage, click on Publish, and similarly create a new one called Blog and Publish:

Now we'll go to Settings and then to Reading:

In Your homepage displays, we'll set A static page; for Homepage, we'll choose Home; for Post page we'll choose Blog, and then we'll save it.

Now we...

Comment Functionality

In this section, we'll add the custom comment functionality.

Let's open up single.php and go right under endif. We'll say <?php comments_template(); ?>:

   <?php endif; ?>

<?php comments_template(); ?>
</div>

Let's save this and reload. We have our comment section now:

Let's say Great Post, click on Post Comment, and it works!

Now this will work as far as functionality goes, but it doesn't look too good, so I want to show you how we can customize this.

We'll create a new page, or a new file, and we'll call this comments.php. If we go back now and reload you'll see there's nothing here, it's reading from this file; if we say Test and reload, we get Test:

So it's up to us to customize how we want this to work.

There's actually some helpful code in the documentation at...

Summary

Great! So that was pretty much it. The purpose of this project wasn't to build a beautiful theme, it was to really get you familiar with the different files that we need to create the syntax, the different functions, and things like that.

We saw different post formats and created design using HTML and CSS. We created a WordPress theme by learning how to display blog posts, single posts, custom archive pages, and different post formats. We also saw how to add an image to the post and dealt with pages, custom templates, and sub navigation. We also worked around theme widgets, custom homepages, and the comment functionality.

So, hopefully you enjoyed this chapter.

In our next chapter, we will build a WordPress theme for the photo gallery.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Learn the basics of WordPress theme development in a step by step manner
  • • Make your themes more dynamic by integrating components of Bootstrap and JQuery
  • • 5 carefully-selected projects to help you get beyond the theory and create highly marketable WordPress themes from scratch

Description

WordPress has emerged as a powerful, easy-to-use tool to design attractive, engaging websites. Themes play a big role in making WordPress as popular as it is today, and having an eye-catching, fully-functional theme could separate your website from the rest! This book will help you take your first steps in the WordPress theme development process, with 5 different projects centered around creating unique and responsive WordPress themes. Start with creating a simple WordPress theme using HTML5, CSS, and PHP. Then, you will move on to incorporate different APIs, widgets, and tools such as Bootstrap and jQuery to create more dynamic and highly-functional themes. Whether you want to create a photo gallery theme, a highly customizable e-commerce theme, or a theme designed to suit a particular business, this book will teach you everything you need to know. By the end of this highly interactive book, you will have the required mastery to develop WordPress themes from scratch.

Who is this book for?

If you are a blogger or a WordPress user who wants to learn how to create attractive, eye-catching WordPress themes, this book is for you. A basic understanding of HTML5, CSS, PHP, and some creativity is all you need to get started with this book.

What you will learn

  • • Simple and advanced themes – covers basic syntax and files along with archives and search pages
  • • Photo Gallery – add simple animation and use the W3.CSS framework to design a photo gallery theme
  • • Wordstrap – incorporate Twitter Bootstrap into the theme and use the WP_NavWalker class
  • • E-commerce theme – build an e-commerce theme using the Foundation framework

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 29, 2017
Length: 458 pages
Edition : 1st
Language : English
ISBN-13 : 9781787286641
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 29, 2017
Length: 458 pages
Edition : 1st
Language : English
ISBN-13 : 9781787286641
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 99.97
Learn to Create WordPress Themes by Building 5 Projects
€29.99
WordPress Plugin Development Cookbook
€32.99
WordPress Complete, Sixth Edition
€36.99
Total 99.97 Stars icon
Banner background image

Table of Contents

5 Chapters
Creating a Simple Theme with WordPress Chevron down icon Chevron up icon
Building a WordPress Theme Chevron down icon Chevron up icon
Building a WordPress Theme for Photo Gallery Chevron down icon Chevron up icon
Building a Twitter Bootstrap WordPress Theme Chevron down icon Chevron up icon
The Foundation E-Commerce Theme Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(5 Ratings)
5 star 40%
4 star 0%
3 star 60%
2 star 0%
1 star 0%
Cory P Jun 09, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book was in like new condition as described. It was well written and easy to understand.
Amazon Verified review Amazon
Moses Gouveia Jun 04, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent for the growing developer.
Amazon Verified review Amazon
A Real Customer May 17, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Unfortunately after being written it should have had someone read through and follow the instructions.It has a lot of:"Here we added a link to the stylesheet" - but the code shows no link and it just appears in code several pages later"As you can see in the following screenshot" - then there is no screenshot"Here you should add 'the_date()'" - but then the screenshot must show the result using 'the_time()' because 'the_date()' will only show the date for one post. If the have two posts posted on the same day (which this project does) then using 'the_date()' will only show the date on the first one, the second will be blank and you'll be left thinking you must have done something wrong and spend 10 minutes googling for help.The screenshots in this book were taken between 12/12/2017 and 21/12/2017 and the book was published on 29/12/2017 - I think it's fair to say it was rushed in order to be put through on time and as such misses a few of the finishing touches which would make it much better.
Amazon Verified review Amazon
Doug Nov 16, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Large portions of this book are unreadable. The kindle formatting has one letter per line.
Amazon Verified review Amazon
Amazon Customer Aug 02, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I am only 50 pages into the book, still in Chapter 1. The text needs polish. It would benefit from an editor and a test reader. If you already code PHP, HTML, CSS and WordPress and just want to know how to create WordPress themes, then you will probably adore this book. However, I am a little rusty/weak in some areas, so I struggle.I get the feeling the author didn't intend the book to require quite so much expertise, but certain details are lacking. For instance, On page 29 we are directed to add a header tag in the HTML file. It shows what to add, but not where to add it. OK, I figured it out, but a single line of pre-existing text in the example to show *where* would have been easy to add and very helpful. I guess nobody else is typing, but just looking at the finished code downloaded from the website.If you try to follow along in the text, you MUST use a really good syntax-aware editor for typing the examples. The author says on page 10: "Open the wp-config file using Sublime Text as the editor. You can use whichever editor you feel comfortable with."This reads like "I like to use Sublime Text." What it really means is: USE SUBLIME TEXT (or something equally powerful designed for editing these types of files) because it auto-formats, does syntax highlighting, auto-inserts block closing tags and other things omitted from the example text. But... you know... whatever you are comfortable with. :-)Given all the little errors, I found it odd that there are no errata on the PacktPub website. Perhaps everyone else simply uses the downloaded code rather than going step-by-step as described in the text.I will keep plowing forward. but the book could be much better with just a bit of effort.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.