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
R$49.99 R$173.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (5 Ratings)
eBook Dec 2017 458 pages 1st Edition
eBook
R$49.99 R$173.99
Paperback
R$217.99
Subscription
Free Trial
Renews at R$50p/m
Arrow left icon
Profile Icon Eduonix Learning Solutions
Arrow right icon
R$49.99 R$173.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (5 Ratings)
eBook Dec 2017 458 pages 1st Edition
eBook
R$49.99 R$173.99
Paperback
R$217.99
Subscription
Free Trial
Renews at R$50p/m
eBook
R$49.99 R$173.99
Paperback
R$217.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781787286672
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 736.97
Learn to Create WordPress Themes by Building 5 Projects
R$217.99
WordPress Plugin Development Cookbook
R$245.99
WordPress Complete, Sixth Edition
R$272.99
Total R$ 736.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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.