navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Dreamweaver and WordPress: Building Themes

Dreamweaver and WordPress: Building Themes

with Joseph Lowery

 


In this course, author Joseph Lowery builds a WordPress theme from the ground up using Dreamweaver. The course examines the core structure of a theme, demonstrates constructing and customizing a theme, and explains how to create the site's CSS. The course also covers setting up the single post page, handling search results, and customizing error pages. Exercise files are included with the course.
Topics include:
  • Constructing a theme page
  • Creating a header and footer
  • Building the main content area
  • Activating a theme
  • Developing a page template
  • Archiving posts

show more

author
Joseph Lowery
subject
Web, CMS
software
Dreamweaver CS5, CS5.5, WordPress 3.x
level
Intermediate
duration
1h 47m
released
Mar 09, 2012

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Hi! I am Joseph Lowery, here to welcome you to Dreamweaver and WordPress: Building Themes.
00:10WordPress is among the top content management systems, or CMS, and blogging
00:14platforms in use today.
00:16One of the primary reasons web professionals turn toward WordPress when
00:20creating sites for their clients is its combination of power features and full
00:25design customization.
00:27In WordPress, a site's look and feel is controlled by the theme it uses.
00:32There are two main ways you can customize a theme for a website.
00:36First, you can acquire one of the thousands of available themes and manipulate
00:41the structure and/or CSS.
00:43The other approach to working with themes is to build it from the ground up, and
00:48that's exactly what we're going to cover in this course.
00:50I'll help you understand how the various pieces of the WordPress puzzle fit
00:55together and show you how to use Dreamweaver's power tools to build them
00:59quickly and efficiently.
01:00We'll expand our theme exploration with details on how to create custom page
01:06templates, personalized search results, and more.
01:10Creating your own theme from scratch may be the best way to really get your head
01:15around the types of sites possible with Dreamweaver and WordPress.
01:19Let's get started!
Collapse this transcript
About the exercise files
00:00If you are a Premium member of the lynda.com Online Training Library, you have
00:05access to the exercise files used throughout this title.
00:08Naturally, the information in this course is ultimately intended to be applied
00:12to your own web pages.
00:14However, you may find it helpful to work with the supplied exercise files to
00:18practice the step safely and without creating your own examples.
00:23To begin using the files from the site, download them, extract them, and then
00:27store those files in a convenient location, such as your desktop.
00:32The Exercise Files folder is organized by chapter, although not every
00:37chapter has a folder.
00:39In each chapter, it's broken down into the various videos that you'll see.
00:44Within the video folders, there are a series of files, typically assets like CSS
00:49style sheets, images, and source code,
00:53as in this case where we have a PHP file named index. You'll also find a folder
00:58named final and that contains files showing the completed state of the movie,
01:03which you can open up to take a look at and explore at your leisure.
01:06Because we're working with WordPress, which stores much of its information in a
01:10database, it's best to follow the course chapter by chapter in order to have the
01:14most up-to-date data.
01:16However, if you need to jump in at a certain point, I've provided a folder
01:21called JumpIn and within it is an XML file which you can use to bring the data
01:26into WordPress' database table through the WordPress Import feature, found in the
01:32WordPress Dashboard, under the Tools category.
01:35If you are a Monthly subscriber or Annual subscriber to lynda.com, you don't
01:39have access to the exercise files, but you can definitely follow along with
01:43your own assets.
Collapse this transcript
Development environment requirements
00:00Because WordPress is an application that relies on PHP and MySQL,
00:04you'll need to set up a local development environment to work with it.
00:08While going through all the steps to create such a development environment is
00:11beyond the scope of this course, I am going to lay out the requirements and
00:15give you some pointers, including telling you about a freely available lynda.com course.
00:21For WordPress to run, you'll need the following setup, both on your hosted site
00:26and on your local system.
00:28You'll need a web server, like Apache or Microsoft's Internet information server,
00:33known as IIS; a PHP server version 5.2.4 or higher; and a MySQL server,
00:41version 5 or higher.
00:43That will handle all the modern installations of WordPress.
00:46If you're working with a legacy site that uses WordPress 3.1 or below, you can
00:51use older versions of the PHP and MySQL server, as listed here.
00:56Make sure your web site host meets these requirements before you embark on using
01:01WordPress for a site. Most do.
01:04If you need to set up a local development environment, there are several options.
01:08You can install the components, that is, the web server, PHP, and MySQL,
01:12separately or you can install one of several bundled systems that are available
01:16like WampServer for Windows, either in 32- or 64-bit version, as we're using in
01:22this course, MAMP for Mac OS X. MAMP offers two different versions:
01:28a standard and a pro. You really only need the standard version to start. Or
01:33XAMPP for Windows or for Mac OS.
01:38If you're installing the components separately and not in one of the bundles,
01:42I highly recommend that you include a database manager like phpMyAdmin or something similar.
01:48All of the bundled systems include phpMyAdmin.
01:53For further explanation on setting up a local development environment,
01:57see the freely available lynda course by David Gassner, Installing
02:01Apache, MySQL, and PHP.
02:04Next, you'll need to set up WordPress locally.
02:07For detailed explanation, see my course Dreamweaver and WordPress: Core Concepts.
02:13As an overview, here's what you need to do.
02:16The first step is to create a database in MySQL with phpMyAdmin, or a similar app.
02:22The database that's used in the example files is DW_WP_Themes.
02:30Then you'll need to copy the WordPress files that you downloaded from
02:34wordpress.org to a new folder in the web root.
02:38That folder will also serve as the local site root in Dreamweaver.
02:42For this course, a folder is named again DW_WP_Themes.
02:49Then, in your browser, go to localhost/ and whatever the folder name is.
02:55When you do that, WordPress will come back with an indication that it can't find
03:00the configuration file and ask if you want to create it.
03:03Click Yes, and you'll be given an option to enter in some values:
03:07the database name; the server name, which is typically localhost ;and your
03:12username for the database and password.
03:15When your WordPress setup is complete, you should be able to visit
03:18http://localhost/foldername/wp-admin and then log in using your username and
03:30password that you previously specified.
03:33This will give you access to the WordPress administrative site known as the Dashboard.
03:38The final step is to create your Dreamweaver environment.
03:42In Dreamweaver, you'll need to set up a new site with the WordPress files at
03:46the local site root.
03:48You'll also need to create a new testing server in Dreamweaver with these parameters.
03:52Connect using the Local/Network option, point to the site folder, and then also
03:58under the Advanced Tab, choose the PHP MySQL Server Model.
04:03After you click Save, make sure that the Testing server checkbox is selected
04:08in the server list.
04:09That last point is a bit of a gotcha, because Dreamweaver typically selects the
04:14Remote server checkbox by default, and you have to make sure to change it.
04:18Here is how my site looks in Dreamweaver.
04:22I have the site root pointing to the folder that contains the latest version of
04:26WordPress, which at the time of this recording is 3.3.1. Just a quick side note.
04:33The concepts and methods in this course should work fine with future versions of WordPress,
04:38although there maybe some UI changes.
04:40However, for complete fidelity, visit wordpress.org/download/release-archive
04:49to get version 3.3.1.
04:52Once your local development environment is established, you'll be able to
04:55create and develop WordPress sites, as well as work with PHP and MySQL,
05:00separately in Dreamweaver.
Collapse this transcript
1. Building a Theme From Scratch
Understanding the basic WordPress structure
00:00One of the real strengths of WordPress is its flexibility.
00:03You can easily switch the look and feel of your site to one totally different
00:07by just activating a different theme.
00:10New pages can be quickly added for any special purpose.
00:14Content can be grouped by custom tags or categories, added on the fly.
00:18However, all this flexibility comes at a price.
00:22WordPress is a pretty complex application.
00:25In this video, I'm going to explain just how WordPress works, so that you can
00:30get a better grasp of what's required to build a custom theme.
00:35So visitors first requesting the initial WordPress page index.php starts the
00:42whole ball rolling, just like viewing any web page.
00:46The next thing that happens is WordPress activates the themes.
00:50This is actually the first line of the executable source code and the
00:55WordPress index.php file.
00:58WordPress then checks to see which template files are present.
01:01WordPress works with a series of template files that it dynamically assembles to
01:05create the desired page, and it has to know which template files are present so
01:10that it can know which ones to bring together.
01:13Next, it gathers the settings that are stored in the database.
01:17This includes all the default settings and any ones that have been customized,
01:21like the title of the site for example.
01:23Then it retrieves a specified number of most recent posts.
01:28You can set how many posts you want shown through the Dashboard's general settings.
01:33Certain information, like post data, is stored in a variable, and this includes
01:38data about the post, like the title, author, date of post, and comments, otherwise
01:43known as metadata, as well as the content of the post itself.
01:47Finally, it outputs the data into a theme page, according to the coded layout
01:53and CSS styles applied.
01:55Developing this presentation layer will be the main focus of this course.
02:00As you can see, there's a lot going on, and it happens in the blink of an eye.
02:05And this is just for the homepage.
02:07WordPress is capable of displaying all types of pages, including those for
02:11specific posts, archives, posts under a particular category, or with a specific tag.
02:17One of the key paths to developing custom themes is to understand what happens
02:23when these and other types of pages are requested.
02:27Remember this step where WordPress checks to see which template files are present?
02:31A theme doesn't have to have a specific file for every type of page.
02:37WordPress has a template hierarchy built-in that determines what to do if a
02:42needed file is missing.
02:43Let me give you an example.
02:46Let's say that a site visitor clicks on the author's name, mine in this example,
02:51to see all the posts that he wrote.
02:53First, WordPress looks to see if there is a template that combines the author
02:57prefix with the author's so-called nice name, defined in the user's profile, and
03:03uses that if there is.
03:05If there's not, it looks for one with the user ID.
03:09If that's not there, it tries to display the generic author.php template.
03:14Should that template be unavailable, it looks for a theme-specific archive.php.
03:20And if that's not there, ultimately, it uses the index.php template.
03:26The WordPress template hierarchy covers all the different used cases.
03:30You can see a complete diagram on the wordpress.org site.
03:34The template hierarchy gives custom theme developers a tremendous degree of control.
03:39You can basically decide how much you want to fine-tune the layout of your theme
03:43on a page-by-page basis.
03:45Now that you have a better understanding of how WordPress works with themes in
03:49general, you are ready to dive a bit deeper into how an individual theme page
03:54is constructed.
Collapse this transcript
Constructing a theme page
00:00A standard HTML page is a single file of code with numerous dependent files like
00:05images and style sheets.
00:07A dynamic HTML page, like those used by WordPress, consists of many code files,
00:13dependent files, and data from a database assembled on the fly.
00:17In this video, we will explore the components of a basic WordPress theme page
00:22and how it all comes together.
00:23The individual files that make up a theme page are called template files,
00:28not to be confused with Dreamweaver templates.
00:30And while it can very widely depending on the theme, a basic theme homepage like
00:35the one we are going to build is comprised of five different template files.
00:40The first elements of a theme page come from the Header template file, stored as header.php.
00:47This includes the doctype and opening HTML tag, as well as the complete head section.
00:53It also typically includes the opening body tag up through the header section.
00:58The next section of the page comes from the index.php file, which is responsible
01:03for displaying the main content, usually one or more posts.
01:07The index.php page, because it is the main one in the folder, also contains
01:12WordPress PHP functions to integrate other page areas, such as the header.
01:17WordPress themes very often use at least one sidebar.
01:21That content comes from the appropriately named sidebar.php file.
01:27In WordPress, sidebars frequently are used to contain widgets.
01:30Widgets can do many things, like providing navigation links to archives of
01:35posts, categories, or tags.
01:37The generally accepted practice in building a theme is to set up your sidebar to
01:42show a default set of widgets which can be replaced by those selected in the
01:47WordPress Dashboard.
01:49The footer.php file obviously holds the footer section of the page,
01:53but it also includes the closing tags to the body HTML and any other tag opened
01:59but not closed in header.php or index.php.
02:04Finally, the main CSS style sheet, by default named style.css, is the primary
02:11repository for the CSS rules which handle the presentation of the theme page.
02:16Additionally, style.css is where information about the theme itself--
02:21it's name, author and so forth--are stored.
02:24You'll need those details properly formatted in order for your theme to be
02:28activated by WordPress.
02:30Those steps are covered in the Presenting the Theme chapter of this course.
02:34Several of these files--header, footer and sidebar--are frequently used to create
02:39other types of pages.
02:41As explained in the "Understanding of the basic WordPress structure" video earlier
02:45in this chapter, WordPress follows a template hierarchy to determine which
02:50layout to use for a particular type of page.
02:53As a custom theme builder, you can control how specific pages are presented by
02:57creating custom template files, like those shown here.
03:01I want to take a moment to describe the top two template files on this list.
03:06The archive page is, as determined by the WordPress template hierarchy,
03:11extremely important.
03:12It is essentially the fallback template for 6 different page types: Author;
03:17Category; Date; Tags; Taxonomy, which is a more robust type of tagging system;
03:24and Archive itself.
03:26If you don't create a template file for any of the other page types, you need to
03:30at least create an archive.php file.
03:33The Custom Page Template File, stored as page.php in the Theme folde,r is similar
03:39but more open-ended.
03:41Any page created via WordPress' Page interface found in the Dashboard relies
03:46on the custom page template.
03:48So, if you wanted to banish the sidebar from all of your custom pages, page.php
03:54is the place to do it.
03:56Moreover, you're not restricted to using just one custom page template.
04:00I recently worked on a project that employed over 18 custom page templates.
04:05There is no limit to the number of templates you can use.
04:08Now that you have a better grasp of the different parts of the theme page,
04:12you're ready to start building the files from the ground up.
Collapse this transcript
2. Creating the Core Elements
Setting up for a custom theme
00:00Before we can get started actually creating the template files that form our
00:03theme, we need to take care of a couple of housekeeping chores: one minor, but
00:08essential, and another, a handy Dreamweaver helper.
00:11Each thing you create or install is contained within its own folder.
00:16That folder is in turn stored within the appropriately named themes folder, found
00:22within the wp-content folder.
00:25So, the path to a theme folder is wp- content/themes and then the specific
00:34folder name for whatever that theme is.
00:36Now let's create the folder to hold our theme.
00:40So expand the wp-content folder and then expand themes once you see that,
00:47right-click or Cntrl+Click on the themes folder, and choose New Folder.
00:53Change that name to the name of whatever you want your folder to be called.
00:57Now I'm going to call mine custom.
01:01Now that takes care of the somewhat- trivial-but-absolutely-essential task.
01:05Let me show you a tool that will make sure we're getting all the help and coding
01:09WordPress pages that Dreamweaver can offer.
01:12Before we implement that change, I want to show you where we are at now so you
01:16can appreciate what's being added.
01:18I'm going to open up the twentyeleven folder, which is one of the default themes
01:24that comes with WordPress.
01:25So now I'm going to scroll down within the twentyeleven folder, till I find
01:29index.php, double-click to open that up, and here you see the very first
01:35function is a get_header.
01:37This is the function that is called to bring in the code contained in header.php.
01:42But I want to show you what happens when we start working within PHP code in
01:47Dreamweaver in this default state.
01:49So I'm going to go ahead and put my cursor right within the php block so I can
01:54enter in some php code, and start to type in this custom WordPress function.
01:58So I will type get_, and let me go ahead and invoke the code hints. You can do
02:04that by pressing Ctrl+Spacebar, both on a Mac and the PC.
02:08And now when I type my H for header, you see the code hint that comes up is
02:14get_headers plural.
02:15Now that is a standard PHP 5 function,
02:19so that's why it's listed here, but you don't see the WordPress-specific
02:24function, get_header.
02:26Now let's bring in that tool that will add in WordPress-specific code hinting.
02:31So I'm just going to hit Escape here and get rid of my code line.
02:36Okay, so let's go up to Site and then choose Site-Specific Code Hints.
02:42When the Site-Specific Code Hints dialog box opens, Dreamweaver has already
02:47looked at your site and sees that the structure is one that it's familiar with
02:51and identifies it as WordPress.
02:53Now it also has options for Drupal and Joomla or a completely different type of
02:59structure that can be customized.
03:01So we'll keep it at WordPress. If necessary, you can point to other folders,
03:06even folders within folders that contains other kinds of functionalities and
03:10have Dreamweaver pick up the code hints necessary for those functions.
03:15But for WordPress, all you literally have to do is open this dialog box, verify
03:20that Dreamweaver has identified the structure as WordPress, and then click OK.
03:25Now it's not immediately obvious, but Dreamweaver has added a file to the dialog
03:29box--and let me close wp-content so you can see it here.
03:33And it's the dw_php_codehinting.config, which if we open up, you'll see
03:42contains some core functionality that we don't even have to understand at all.
03:46You will also notice that the file is automatically cloaked, so it will never be
03:50uploaded to your server.
03:52This is a local development option only.
03:55So now that our Dreamweaver PHP code hinting has been added, let's try
03:59that get_header again.
04:01So I'll go back to my code, type in get_, and this time I'll hit Ctrl+Space
04:08again. And now when I press H, get_ header isn't my list of code hints, as well
04:13as get_headers, but you also see all the other WordPress functionality and where
04:20it is located within the WordPress theme.
04:23If we enter wp_ and press Ctrl+Spacebar again, you will see an entire library of
04:31WordPress functionality. So let me press Escape and then close this file without
04:36saving it. So now we've got our theme folder created and we've turned on
04:42site-specific code hints for WordPress in Dreamweaver.
04:45We are ready to begin building the template files for the custom theme.
Collapse this transcript
Building a header
00:00The header template file in WordPress typically contains--you guessed it--the
00:04header section of the page.
00:06However, you may not have guessed that it also contains the entire
00:10meta-document area, the head tag.
00:12As such, it's an appropriate place to begin our theme creation.
00:16So we'll start by going up to File > New, and then when the New Document dialog
00:22box opens, choose Blank Page, Page Type PHP, and set the DocType to HTML 5. Then click Create.
00:35Now we're going to transform this relatively simple blank page into a header
00:41file that's filled with PHP code.
00:44To help the process, I'm going to open up the header_code.php file that I have
00:50in my exercise files, found in Chapter 2, folder 02_02.
00:58This asset file has snippets of all the PHP and other code that we'll need to
01:03integrate into our HTML page.
01:06We'll start by bringing in a language_ attributes function right into the HTML tag.
01:11So I'll select this PHP snippet that you see here, copy it with a Ctrl+C or
01:17Command+C on the Mac, and then flip over to my Untitled PHP page and paste it in
01:25the HTML tag, with Ctrl+V or Command+V on the Mac.
01:30The WordPress-specific language_attributes function inserts the attributes and
01:34values for the proper language, like lang=en for English and text direction,
01:40left-to-right (LTR) or right-to-left (RTL).
01:44So now, we need to work on the meta tag that you see following the opening head tag.
01:49Instead of having charset equals a specific value, we can put in a
01:54WordPress-specific function that will integrate the charset defined in the settings.
01:59So I'm going to remove this value and then go over to my assets page and select
02:07php bloginfo('charset'). Copy that and then paste it in.
02:14The language_attributes and character_ set functions are pretty straightforward.
02:18The title, however, because it has to adapt to a variety of pages, is a bit more detailed.
02:23So I'm going to erase my Untitled Document placeholder, and now let's go take a
02:29look at the PHP code.
02:30We'll be dropping in this code block right here, but before we do, I wanted to
02:36step through it so you'd understand what was going on.
02:39In this first line, line 6, we set up a couple of variables: page and paged.
02:45Next, there is a wp_title function and this sets up the separator to output--
02:51in this case, we have a bar--and where that separator is going to come,
02:55whether it comes to the left or to the right.
02:58That's the third argument that you see there.
03:01The middle argument, true, is a Boolean, which if not true, returns the value as a PHP string.
03:08Otherwise, the value is just echoed.
03:11Next, we'll get the actual name of the site, using the function, bloginfo.
03:16You'll see bloginfo and then its parallel, get_bloginfo, which is on the next
03:21code line, all throughout WordPress.
03:24bloginfo automatically echoes the string.
03:27get_bloginfo, on the other hand, gets the string for evaluation and possible output.
03:33And as you can see in the next series of lines, line 9 through 13, we pull in
03:39that information, the description, and if we're on the home page and it's the
03:44front_page, we'll output it using an echo statement that's shown on Line 11.
03:49If on the other hand, we're in a page document and the page is greater or equal
03:54to 2, we'll do something different and put out the page number.
03:58So let's copy that block and then put it into the title. All right!
04:04I'm going to go ahead and save my file now since we've got a little bit of code on the page.
04:10We're not quite done yet.
04:12I'll choose File > Save.
04:13Then I'm going to go into my site root, into the wp-content folder, into the
04:20themes folder, into our new custom folder, which so far is empty.
04:25We'll put in our first file, and it is header.php.
04:31Save that file, and now let's continue.
04:34Next, after the title, I'll create a new line so we can add in our style sheet information.
04:39Let's flip over to header_code and copy the line, bloginfo ('stylesheet_url'),
04:46which is just the PHP that we'll need.
04:48So I'm going to copy that, and let's enter in our link tag, add in the relative
04:55attribute, and we'll make that a style sheet. And I'll use Dreamweaver's
05:00code hinting here to speed this along.
05:02Enter the type, which is text/css, and then a media tag, and we want this for all
05:10at this point. And finally, the href.
05:15Now this is where we're going to paste in our copied PHP code.
05:19And here, again you see that we're using the bloginfo, which you'll
05:24remember just echoes the value that's returned, and the argument this time
05:28is the stylesheet_url.
05:30My quote got pushed down to the next line, so I'll press Backspace to
05:33delete that line return, and then position my cursor after the quote and close out the link tag.
05:38All right! Now we're going to add in another link, and this one will be for the pingbacks.
05:45A pingback is in essence a verified remote comment that allows users to easily
05:50show links between blogs.
05:52So the coding to this is similar to the style sheet.
05:56We do a link, relative, and this type is pingback, and the only other argument is an href.
06:05So I'll put in the href, and now let's go back to our header_code and pick up
06:11that value. And it's very similar to what we had before for stylesheet,
06:17again using bloginfo.
06:19This time I'll try not to copy the line return so we won't have that problem, and
06:23you'll go in and paste it in. Looking good!
06:26Now we can close out the link tag.
06:28Now another element you'll commonly see within the head are
06:32conditional comments.
06:33Conditional comments are targeted towards versions of the Internet Explorer
06:37browser, to give them more modern functionality or to help them with specific CSS issues.
06:43In this case, we're going to add in a conditional comment that will make it
06:46possible for versions of Internet Explorer earlier than 9 to work with HTML5 tags.
06:52Any other conditional comments you need to add could also go in this area.
06:56So I have that entire conditional comment block written out in my header_code
07:00file, and I'll copy that and bring it into my header.php, right after the
07:08pingback link, paste that in, and here you can see that it opens with a
07:13conditional comment directive:
07:15if the version is less than IE9, put in this script tag, and this script tag
07:21will bring in the needed JavaScript file.
07:23Now we're using a WordPress function called get_template_directory_uri to return
07:29the proper directory path.
07:30Next, we're going to add in a little more JavaScript, this time outside of the
07:34conditional comment.
07:35So I'll go past the endif and go get my PHP code from the header_code page.
07:42Copy line 24 and then go back and paste it in.
07:49And what this PHP snippet does is it checks to see if the WordPress page is a
07:54single page using the is_singular function and if the option
07:59thread_comments is enabled.
08:02And if so, then use another WordPress function called wp_enqueue_script to bring
08:08in the comment-reply JavaScript file.
08:11The wp_enqueue_script function checks to see if the named function has already
08:16been loaded, and if not, loads it.
08:19It's WordPress' way of making it safe to add JavaScript.
08:23The final bit of PHP to go into the head area calls a WordPress function,
08:27wp_head, which is used by many, many plug-ins.
08:32If it's not there, the plug-ins won't work.
08:34Here it is in my header_code.php file, and I'll copy that and then paste it in,
08:46right after our last PHP code block. All right!
08:49The head section is complete, but we're not quite done.
08:52We still need to add the opening tags for the body of the page and the header itself.
08:57I'm going to scroll down a little bit.
08:59So I'll place my cursor within the body tag, make a space, and then bring in some PHP code.
09:06Let me go get that snippet, which is php body_class(). Copy that and insert the code.
09:18This function inserts a class attribute with a series of values that serve to
09:23identify a page and to allow custom styling.
09:27The classes that are inserted depends on what kind of page it is.
09:31WordPress will dynamically change the classes accordingly, thus allowing you to
09:35style different pages differently.
09:38Next, we'll add an opening tag for a div that will wrap the entire page, a
09:42common strategy which is great for applying a width and if necessary,
09:47centering the page.
09:49I'll just enter this one in by hand.
09:52It's a div with an ID that I like to use called outerWrapper. And we'll
09:58close off that tag.
10:00Now normally, if I were coding just a straight HTML or PHP page, I would go
10:06ahead, enter a couple of lines, and then enter the closing div tag.
10:10We don't want to do that here because, as I've explained before, the header is
10:15only going to have the top part of the page.
10:18The closing div tag will actually appear in the footer.php page.
10:23So let me erase my little div there.
10:26The final tag we'll put on this page is sort of why we're here, the header tag.
10:31Now you could just put in a div with an id of header, but since we're using
10:35HTML5, let's put in the header tag.
10:40This one, because it's completely contained within header.php, I will close out.
10:45Let me go ahead and select that and then tab it in so that it's within
10:52my outerWrapper div.
10:54Now, let's put a little bit of content in here that will help identify the page
10:58with the site name that is linked to the home page.
11:02This is easily replaceable with a logo, should the design call for it.
11:06But it's very common to see a basic theme starting out this way. All right!
11:11Let's go to my asset file and I'll select the entire h1 tag, copy that, back to
11:19header.php, tab in, and paste it in.
11:24This is a standard h1 tag and within that is an anchor tag.
11:28Within the anchor tag is an href attribute that uses the get_option function to
11:34pull in the web address of the home page.
11:37Note that there is a trailing slash mark here that's added after the path to
11:42the home page is given.
11:43And within the anchor tag, we have the site name itself, which is, again, pulled
11:49in using the bloginfo function.
11:52Now, let's add some basic functionality.
11:55I'll put in a line return after the h1 tag, and I'll insert a nav tag with a
12:01class of mainMenu that I'll be able to reference later.
12:08And again, because this is all within the header.php file, I'm going to close
12:12out that nav tag. Now we'll put in a WordPress function that will pick up any
12:18custom pages you create and display them as a linked ordered list.
12:22With my cursor positioned between the opening and closing nav tags, let's switch
12:27over to header_code.php to get the final snippet of code, and there you see the
12:32function wp_nav_menu.
12:36I'll copy that and then paste it in.
12:40We'll add the necessary CSS styling for our nav bar in the "Building up the CSS"
12:45video found in the Presenting the Theme chapter.
12:48Finally, it's important that you remove the closing tags of the page, because
12:53those will be added in another template file.
12:56So I'll scroll down, select the closing body and HTML tags, delete them, and now
13:02we're ready to save our page again.
13:04So I'll just press Ctrl+S or Command+S on the Mac.
13:08And now the first part of our custom theme is complete, and you're ready to
13:12move on to the next part, where we'll close out the tags opened in this, the
13:16header.php file.
Collapse this transcript
Crafting a footer
00:00The footer template file, which will be saved as a footer.php, has two main functions.
00:06First, and pretty obviously, it contains the footer area, which is common across the site.
00:11Second, the file contains closing tags for elements initialized in
00:16the header.php file.
00:18All in all, it's a very simple page but critical to any theme.
00:22So I'll start by going over to my Files panel and right-clicking on the custom
00:27folder, creating a new file, naming it footer.php, then opening it up.
00:34The first step is to remove all the code except for the closing two tags.
00:39So I'll select everything from DOCTYPE all the way down to the opening body tag,
00:44press Delete to remove them, and then hit a line Return, just open up a little
00:48space so we can start to add in our code.
00:52Let's start here on line one by adding in the HTML5 footer tag, and then I'm
00:59going to add a couple of lines and close out that tag, and I'll place my cursor
01:04in between the opening and closing and press Tab.
01:07Now I'm going to open up a file called footer_code.php that's found in the
01:13Exercise files/Chapter 2/subchapter 02_03 folder. And this has all the code for the footer,
01:23but all I need now is my paragraph tag that has the PHP and WordPress
01:30functionality written into it, so I'll copy that.
01:34Move back to my footer.php page, paste it in, and let me walk you through
01:38this really quickly.
01:40It starts with just some plain text, Copyright. There is the ©
01:45which is the character entity for the Copyright symbol, followed by a little
01:49mixture of PHP and WordPress functionality.
01:52Of course, you could add any sort of placeholder content, but since we
01:56are working in a PHP page, we'll add in some code that will generate the
02:01year programmatically.
02:02First we see the date functionality, which is set to return just the year,
02:08followed by a space, followed by a WordPress function, bloginfo, to get the name of the site.
02:14Now we're ready to finish off the tag that we began in header.php.
02:19So I'll make a line return after the closing of the footer, and we'll close out the div tag.
02:27And one thing that I found helpful when you're working with WordPress template
02:30files is to always include a comment that notes the end of any div, so you could
02:36follow the structure of it in your code.
02:38So because we're closing out the outerWrapper tag here, I'm going to enter in an
02:42HTML comment that will say end OuterWrapper.
02:49Let's save our page and now with the header and footer pages complete, we are
02:54ready to move on to the meat of the web page sandwich, the content.
Collapse this transcript
Completing the sidebar
00:00The sidebar is a common feature in blogs and is typically used to display blog-
00:04related navigation, such as links to recent posts, categories, and tags.
00:10The entities displaying these links are referred to as widgets.
00:14In this video, I'll show you how to set up a default set of widgets for your
00:17custom theme that can be easily replaced in the WordPress Dashboard once
00:22the theme is activated.
00:24So let's create a new page called sidebar.php in our custom theme folder.
00:29I'll right-click on custom, choose New File, and then name it sidebar.
00:35Now let's open up that file, and the first thing we'll do is delete all the code that's there.
00:41I am going to start by putting in a div with a specific class of widget-area.
00:47This class is one that is commonly used in WordPress themes.
00:50We'll close the div, press Return a couple times, and then close out the div entirely.
00:56Next we want to add some PHP code that will display the default widgets only if
01:02none are defined in the Dashboard.
01:04To do this, we'll draw on WordPress' dynamic sidebar function. And to help me I'm
01:10going to open up my sidebar_code.php file, found in the 02_04 folder, which is of
01:17course within the Chapter 2 folder of the Exercise Files.
01:20So now I'm going to grab this first php code block, copy it, and let's put it in
01:28indented within the div.
01:31Let me open that up a little bit and indent the final line as well.
01:35Now this is a standard php if statement. And the condition that is being checked
01:40reads if the dynamic_sidebar, sidebar -1 is not found, then do whatever is
01:46contained within the if statement.
01:48Now you don't have to go with sidebar-1. I'm going to go ahead and change that
01:53to a custom name, call it Sidebar Widgets.
01:57The name Sidebar Widgets now reflects the name of the sidebar we'll register in
02:01the functions.php file a little later.
02:05Now let's go ahead and add some basic widgets that will be on the page until
02:09someone decides to add some new widgets through the WordPress Dashboard.
02:14I'm going to wrap each of my widgets within an HTML5 tag called an aside.
02:18I will place my cursor at the end of the PHP if statement, hit Return and then
02:23Tab, and enter in the code for an aside tag, give it an id of search and a class of widget.
02:37Close that opening tag and hit Return and close out the aside tag entirely.
02:44Now WordPress has a specific function that will return an entire search form.
02:49Let's pull in that code from our sidebar_code.php file.
02:55I'll copy and then within the aside tag, paste it in.
03:02This function displays the search field End button, so we can take advantage of
03:06WordPress' built-in search functionality.
03:09Next, let's put up a series of links for any posts written in the previous month.
03:14I'm going to create another aside container now and we'll put that after the first one.
03:21This one will have an id of archives, but the same class as above, widgets.
03:30Close that opening tag.
03:33Enter a few lines and close off the aside.
03:36Now the search function actually has a built-in title.
03:39For this widget we'll need to add in our own title, and I'm going to put
03:43that within an h3 tag.
03:45We will give this a specific class of widget-title, and I'm going to hard-code in
03:56the title name here, call it Archives.
03:59Most of the widgets that you will add in through the Dashboard will allow you to
04:03put in your own custom title.
04:06So let's close off the h3 tag.
04:08The WordPress function that we will use to return all of our archive links
04:13returns them in the form of a li tag.
04:17For that to work properly, we'll need to add a little bit more structure
04:21around it, the ul tags.
04:23So I'll hit Return and then just put in my opening and closing ul tags.
04:30You could give this a class name if you wanted to, but because it's within an
04:34aside with a specific id, you really don't need to.
04:36Now we're ready to drop in our php code, which I'll get from sidebar_code.php.
04:46Once copied, I'll move back and paste it in, and here we see another WordPress
04:51function, wp_ get_archives, which has a whole range of options.
04:56In this circumstance, we've set it to return a monthly archive, limited to 12 items.
05:01Let me just clean up this one little space here by removing that, and now our
05:06sidebar page is done.
05:08So I'm going to ahead and save it.
05:10I mentioned earlier that we need to create a support file so that the
05:14sidebar will work properly, and that's called the function.php file.
05:19Again, this goes within our custom theme.
05:21Right-click on custom, choose New File, and name that functions.
05:29Open it and remove all the HTML code.
05:33So now I'll open up my helper file functions_code.php, found in the same folder
05:40of the Exercise Files, and here we see a function for registering a new sidebar.
05:46The first thing that it does in line 2 is check to see if the WordPress
05:50function register_sidebar is available to us, and if it is, it sets up the
05:55sidebar using an array.
05:57The name of the sidebar is Sidebar Widgets, which we saw earlier in the
06:02dynamic_sidebar function.
06:04Its id will be sidebar-widgets.
06:07There is a description and other array values which set up what code should go
06:12before the widget and after it.
06:14You can see it is an aside tag with a very specific id, the one that we have
06:19specified here and a specific class, and also array values before and after the
06:24title, the h3 tag that we have used in our hard-coded widgets. All right!
06:29Let's copy this code block, move over to functions.php, and paste it in.
06:37I'll save that file, and our first function in our functions.php file is ready to go.
06:44Although we have worked with a fair amount of code, this is among the most
06:47basic of sidebar implementations.
06:49You can easily add multiple widget areas as well as static content,
06:52but it is a good starting point for the widget-based content that goes into
06:57our custom theme.
Collapse this transcript
Creating the main content area
00:00Now we are ready for the main act in the template file presentation, the
00:04content. And with a blog-based program like WordPress, content means posts.
00:09To present the most recent posts, WordPress relies on code known as the loop.
00:14In this video, we will step through the loop one line at a time, so you can see
00:19how the typical content section is constructed and how all the other pieces of
00:24the template file puzzle that we've built in the earlier videos of this chapter
00:29are brought into play.
00:30Let's create a new file in the custom folder. Again right-clicking on custom,
00:36choosing New File, and this time we will name that index.php.
00:41We will open it and remove all the existing HTML code.
00:49Let's start out the index.php page by displaying the opening section found in
00:55header.php, and to do that, we will use a WordPress function called get_header.
01:00So I will enter in my opening PHP tag, type in get_header, followe it with an open
01:09and closed parenthesis and then a semicolon,
01:10and then close out the PHP code block.
01:12Next, we will add an HTML wrapper to hold both the main content and the sidebar.
01:19We will do this in a div tag with an ID of contentWrap.
01:29Now I am going to put in an HTML comment here so that I will know that this is
01:34the end of contentWrap.
01:39Now within the contentWrap div, we are going to put in another div that will
01:44hold just the main content, and this would be another div, this time with an ID of content.
01:56Let's add in our HTML comment here and the content.
02:03Now using PHP code, let's add the basic structure that will display something if
02:09there are any existing posts and something else if there are not.
02:14With this PHP code, I am going to go to my helper file found in the Exercise
02:18Files called index_code, and that's found in the Chapter 2/02_05 folder.
02:25I have included all the PHP code that you will need in this exercise file asset,
02:31and I have already entered in the get_ header function, so now I am going to just
02:34copy this if-endif statement and bring that into my index.php file and place it
02:42within the content div.
02:44Let's clean that up a little bit,
02:47inserting it so that it's a code block. And I will add a couple of lines on
02:53either side of the if statement and the else statement.
02:58If this condition is met, have_ posts, we want to cycle through them.
03:02This is done with a PHP while loop.
03:06A WordPress function called the post is used to iterate over any existing posts
03:11that are found and retrieve their information from the database.
03:15Let's go get that code block from the index_code.php file.
03:20Here is my while loop. I will copy and then paste it in the appropriate place here.
03:30Let's move that endwhile statement over a little bit and open it up.
03:35Now let's start to apply some of the information found in each post by creating
03:40an article container that has the classes and ID for each posts.
03:44So I will position my cursor within the while loop, and let me get the relevant
03:49code from index_code.php.
03:52Here is my HTML5 article tag with a post_class function inside of it. And we
03:59will paste that in, and again, do a little clean up here.
04:04This first PHP function, post_class here, as you might expect, puts in the
04:09class attribute as well as any classes that have been assigned to this particular post.
04:14The ID that's provided here combines a static value, post with a hyphen
04:20following it, and the ID of the actual post.
04:24The first element within this article is going to be the title, which will be
04:28linked with what is called a permalink or a permanent link.
04:32This will allow the user to click the title to go directly to a single-page
04:36version of the post.
04:38So with my cursor in the article section, let's go to index_code.php, and I'll
04:45grab my h2 tag with the PHP code inside.
04:49Copy that, paste that in, and here you see within the anchor tag, the href
04:55attribute that is pointing to the WordPress function, the permalink, followed by
05:01the_title, and this of course puts in the title.
05:04Now let's add some meta information about the post, including the date it was
05:08posted on and the author.
05:10We will hit Return here, go to index_code.php and pick up the div tag that you
05:17see here with a class of meta, copy that, paste it in right after the title.
05:24I will select it and then clean this up a little bit so you can see it more
05:29easily. And here you see a combination of static HTML and PHP.
05:34The first line outputs the day that it was posted on.
05:37This WordPress function that you see here, the_time, uses standard PHP date
05:42formatting and would display the date with the full month name, the day with an
05:47ordinal suffix--that's a th in 7th or st in 1st--as well as the full year.
05:54An example date would be March 31st, 2012.
05:58So now it's time to add the actual post content.
06:01We will put it in its own div for finer CSS control, and I will put that
06:06after the meta tag.
06:07We will create a div with a class of entry. That's pretty much the standard
06:15WordPress class that's used for each post.
06:17We will close up the div, and then within it, we will use a PHP function to
06:25pull in the content. And because WordPress likes to keep things simple, this
06:32function is called the_content();.
06:40The final part of our post will contain a bit more meta data, specifically any
06:45tags or categories that have been assigned to the post, as well as links to any comments.
06:51Let's grab that from the index_code.php file, and here you find it as a div with
06:57a class of postmetadata. Copy that, bring it in right after entry div, paste
07:05that in, and then select the bottom part and tab it over so that everything is in
07:10line. And now let me break down what's happening within the postmetadata div.
07:15The first PHP code block returns the tags and the arguments set up the initial
07:20string that you will see, the word, tags followed by a colon
07:24and a space, and the separator between each tag and that is in this second
07:30argument, a comma and a space, and then at the end of all the tags, a line break.
07:36Next, we see a bit of code that outputs what categories it might belong to.
07:41And again, the separator is given as an argument. Here it's the comma, followed by a space.
07:46The final bit of PHP here uses the function comments_popup link.
07:51Its arguments will detail what to output if there are no comments, if there is a
07:57single comment, and if there are more than one comment.
08:00The character entity that you see here, »,
08:06is the right angle quote or the right-pointing double angle braces.
08:10Now we have completed all of our code within the while loop, and I will just
08:14clean up some extra spaces here.
08:18And now we come to the else condition.
08:20We have satisfied what happens if we do have posts, but we want to let people
08:25know if there are no posts.
08:27So I am going to add in an h2 tag right after the php else clause and
08:34simply say Not found.
08:39Finally, let's bring in the two other page elements we set up template
08:43files for earlier in the chapter: the sidebar and the footer.
08:48So I will scroll down, and we want the sidebar to appear outside of the content
08:53but within the contentWrap div.
08:56So I am going to place my cursor in between those two closing div tags and
09:01enter in a PHP code block, with a function get_sidebar.
09:10This parallels, of course, the get_header that we entered in at the top of the file.
09:15Now after the contentWrap div, we will add in the get_footer functionality.
09:21Again, php code block, the function get_footer();,
09:28and then close out the code block.
09:32Let's save the page and now the basic coding for your custom theme is complete,
09:38and you're ready to take the next steps towards integrating it into WordPress.
Collapse this transcript
3. Presenting the Theme
Activating the theme
00:00In the previous chapter, we built an entire theme from scratch.
00:03However, at the moment, there is no way to see what it looks like.
00:08If you try to view index.php from the theme folder in either Dreamweaver's
00:13Live view or a browser, you won't see anything, because WordPress doesn't work that way.
00:18And if you view index.php from the WordPress site root, you'll see what ever
00:24theme is currently active. That's the key.
00:27We now have to activate our theme and to do that, we need to create one file: a
00:33CSS style sheet believe it or not, with a special comment that will enable
00:38WordPress to recognize the theme and make it possible to activate.
00:43So let's create that file by going to File > New, choosing a Blank Page with a
00:49Page Type of CSS, and click Create.
00:54When that opens, I'll delete the existing code and let's save the file, and I
01:03want to put it in my wp-content folder, in the themes folder, in my custom theme
01:10folder, where the five other files that I created already exist.
01:15And I'm going to name it style.css.
01:21That special comment I mentioned needs to be at the very top of the style.css
01:26file, and that's why I removed the existing code.
01:29Now let's add in a CSS comment with /* and then I'll create a couple of lines
01:38and close that off with */.
01:42Okay, so now we can put our special comment within that.
01:45We will start off with the theme name. And the syntax here is very critical.
01:50We want to enter it exactly like this, with uppercase letters, Theme Name
01:55followed by a colon,
01:56and a space, and I'm going to call this Custom Theme.
02:00You can use spaces in the theme name without a problem.
02:03In the next line we'll put on the web address for the theme, and this time I'm
02:07going to put in lynda.com as the URI. Typically this would be the web address of
02:13the author. So Theme URI:
02:16and you put in the full web address. This makes it linkable. A brief
02:24description with the keyword Description, and I'll put in a custom WordPress
02:32theme, comma, built from the ground up.
02:42Next is the author line with the keyword Author. I will enter my name. And
02:50finally, we put in the Version, and we will call this 1.0.
02:54All right, we save our file, press Ctrl+S or Command+S on the Mac.
03:01There are other attributes you can add, but this is good enough for now.
03:04Now, let's head over to the WordPress Dashboard and take a look at our Themes panel.
03:10In this latest version of WordPress, they have reorganized the Dashboard UI
03:14so no longer do you have the expanding administrative menus on the left;
03:19instead, they pop out.
03:21So I will go to Appearance and there you say Themes. It makes for a much quicker
03:26use of their administrative interface. And now at the top of the page you see
03:30the current theme that's been activated and that's Twenty Eleven and if we
03:35scroll down a little bit, you will see other themes that are available, including
03:39Twenty Ten over here on the right and our custom theme.
03:43Now the first thing you'll probably notice is that there's no screenshot there.
03:46Not to worry. We'll take care of that in a later video in this chapter,
03:50"Establishing a theme screenshot."
03:52For now, let's go ahead and activate it and you will get a message indicating
03:58that the new theme has been activated.
03:59Let's head back to Dreamweaver to check it out in Live view.
04:03To see it in Live view, we need to go to the site root and open up index.php.
04:11I'll switch over to Design view and then enter into Live view. And there is our
04:16theme, completely unstyled at the moment, but there it is.
04:20Let's make sure that all of the sections are there.
04:23Here we have the header, the first bit of navigation where we see Sample Page. Hello World!
04:28is the first post.
04:30You can see that it has the date of the post, as well as who posted it, the
04:35content and our meta-information, the Uncategorized category that is now we are in.
04:41There is 1 comment and that's added by WordPress for testing purposes. And then
04:46we move on past the post because there is only that one, to our sidebar, which is
04:51not on the site at the moment because it's still unstyled. But here we see our
04:55Search widget, our archives which is just a single one, our comment archives,
05:00the monthly archives, and so forth.
05:03And then at the very bottom is the footer.
05:06It looks like all of the different sections are there, although I admit, it's kind
05:09of hard to tell without any CSS styling.
05:12And now that you've activated the theme, you are ready to continue work on the
05:15much-needed CSS to get that basic presentation in shape.
Collapse this transcript
Building up the CSS
00:00Time to whip our custom theme into shape with a few judiciously crafted CSS rules.
00:05The goal here is to apply just enough style to make the various page areas and
00:10elements identifiable, while at the same time, laying the groundwork for further
00:15customization ahead.
00:17We can use Dreamweaver to accomplish both of these objectives.
00:20Now, in all, there are seventeen CSS rules to code, so we better get started.
00:26I have opened here the index.php from the site root, and we're in Live view.
00:32Now, we want to go to our style.css page and first, we want to make sure that
00:37Dreamweaver is discovering all of the dynamically related files.
00:41So I'm going to click on Discover here in the Info bar.
00:45You'll get a Script warning from Dreamweaver. Click Yes.
00:49If you've set your testing server up properly, you'll see all the files appear
00:53in the Related Files toolbar up at the top of the page.
00:57If I click on the Show More button, you'll see the full list of them.
01:02I believe there's something like 60 odd files that are included.
01:05However, the only one we're interested in at the moment is style.css.
01:09So I'm going to go ahead and choose that and Dreamweaver will switch to Split view.
01:13The first bit of CSS code I'm going to add is a simple Reset statement used to
01:18level the playing field across browsers.
01:21Reset statements can get quite lengthy, so I have one set up as a snippet that I
01:25can quickly drop in.
01:27The technique for creating the snippet is covered in my course Layouts with CSS
01:32in Dreamweaver, here in the lynda.com Online Training Library.
01:36To access it, I'll go to Window > Snippets to open up the Snippets panel.
01:41Well, I have a custom folder here called CSS that I'll expand, and there's my
01:47Simple Reset, which I'll double-click to insert.
01:50Next, let's add a rule for the body tag with a basic background color to help
01:55differentiate our layout from the background.
01:57So I'll enter a body, open my curly brace, put in a background property, use
02:06the code hints to speed it along, and then just enter in a simple gray color,
02:12CCC, close it out with a semicolon, and then close the body rule.
02:17We'll follow up our body tag rule with a few basic tag rules for the
02:21heading elements, making our h1 through h3 tags bold and setting some
02:26specific font sizes.
02:29First, let's make them all bold, and now let's give the h1 and h2 tags some
02:44specific font sizing.
02:52I'll make the h1 tag 2em and the h2 tag 1.5em.
03:05Now, let's move on to the layout itself, starting with the div surrounding the
03:09layout, which you'll recall has an ID of outerWrapper.
03:15First, let's set the margin to 0 on the top and bottom, and auto for left and right.
03:21This will center the page.
03:26Next, let's add a width.
03:28I'm going to make my width 940 pixels, and now I'm going to add a padding of 10 all around.
03:41Now, let's specify that the background color is pure white, so that it will
03:45be differentiated from the body background. And we'll close off the outerWrapper rule.
03:52Now, if I click into Live view, you can start to see some of these changes being applied.
03:56Let's head back over to the CSS style sheet.
03:59I like to organize my style sheets from the top of the page down,
04:04so let's put in a couple of rules for the header.
04:06You'll recall that we're using HTML5 code, so I don't put in a div with an ID of header;
04:12I just enter header. And I'm going to give it a border-bottom and also a bit of
04:19margin on the bottom, to isolate it just a touch.
04:22So border-bottom first, and let's make this border-bottom a bit wider than normal.
04:29We'll make it 2 pixels.
04:31We'll give it a dark-gray color, and make it solid.
04:36Now, let's add in the margin-bottom, and this we'll make 20 pixels.
04:43Let's close off that header.
04:45Now, let's go ahead and give a special size for the h1 tag that's within the
04:50header. And we'll make this a little bit larger than normal, 2.5em.
05:00Let's tackle the navigation next since it's in the header.
05:04For that, we'll need just two rules:
05:07one to offset the menu a bit, and another to turn the unordered list into a
05:12series of horizontal links.
05:13So we'll enter in the nav tag, followed by its class, mainMenu. And we'll give that
05:23a padding of 5 pixels all around.
05:28Close this rule. And next we'll target any list item that is within the mainMenu.
05:34So again, nav.mainMenu to pull up its class and then enter ul for unordered
05:41list, and li for list item, enter the opening brace. And we want to make sure
05:47that these are shown one after another, so we enter display inline.
05:55There's no need to have any of the bullets appear,
05:58so let's get rid of the list-style by setting that to none, and next we'll set a
06:06margin-right for each list item of 20 pixels.
06:12Let's close out that rule. Okay.
06:14Our header is complete and after the header comes the content section.
06:19If you recall, we have the content wrapper with an ID of contentWrap in place,
06:24so let's style that one first.
06:30We'll give it a width of 100% and an overflow of auto. The overflow
06:44auto declaration is to handle the floating elements I know are within the content area.
06:49Let's set up the first of those, content.
06:54We'll give it a width of 700 pixels, because I want that to take up most of the page space.
07:04Now, because I want my sidebar on the left and because the current code order
07:09has the main content coming before the sidebar, I need to float the content area
07:14to the right, rather than floating the sidebar to the left.
07:18So we'll enter in a float property, followed by right.
07:23Now, if I click over into the document area, you can see that the page is really
07:27beginning to take shape.
07:28I'm going to go ahead and close down my panels a little bit and collapse them
07:32so you can really see how the page is shaping up.
07:38Okay, back to the CSS.
07:41Now, within the content area, each post is contained within an article tag.
07:45Similarly, each widget in the sidebar is within an aside tag.
07:50To keep the spacing consistent, I'm going to add a little bit of whitespace to
07:55the bottom of each of these elements.
07:58So our rule will reference both of those as the selectors.
08:02First, let's address the article tags that are within the content div and then
08:10add a comma. And now let's write out the selector for the aside that's
08:15within the widget-area class. And I'm going to give that a little margin at the
08:25bottom of 20 pixels. Let me close the rule.
08:32Next, I want to isolate the actual content of my posts a bit and at the same
08:37time open up the paragraphs.
08:40Posts, you may recall, are in a div with a class of entry.
08:43So I'll enter in div.entry and then div.entry again, followed by p for paragraph
08:53tag, open our brace, and set the margin.
08:58We'll make it 10 pixels on the top and bottom and 0 on left and right.
09:05Let's close out that rule.
09:06Now, let's turn to the sidebar and give it a width to separate the two content areas.
09:22The 220 pixels width should work out pretty well.
09:25Let's click into the document window and see how we're doing.
09:27Well, I think it looks pretty good, although the search input box needs a little love.
09:32But, how do I target it?
09:33Let's try looking at the WordPress code first.
09:36You'll recall that that is within sidebar.php.
09:39Now, I want to use Dreamweaver's custom filter, found on the Related Files
09:45toolbar, to pull in my sidebar.php file. And I also want to keep style.css here,
09:55so I'll enter in a semicolon
09:57after sidebar.php and then type in style.css. When I click OK
10:04I'll have just those two files up top there.
10:07So now I click on sidebar.php, and you can see the problem here:
10:11if I want to target just this particular input box, there's no way to get to it,
10:17because all I have in WordPress is a PHP function, get_search_form.
10:23So another technique that you can use is Live Code.
10:26First, I am going to go over and save my style.css file, and now I'll switch over
10:31to Source Code and then click on Live Code.
10:35So now, we see the code that's generated and sent to the browser in the
10:40left-hand side of the window.
10:41If I double-click the search text, it will go down to where the input tag is, and
10:47now you can see that I actually have an ID of S that's applied for this
10:52particular search form.
10:53So I can use that as my target.
10:56Let's switch back to style.css. And we're targeting an input tag with an ID of
11:04S. And I want that to be a little bit smaller, so I'm going to make a width of 150 pixels.
11:11Let's click over into the document window and see how that looks.
11:16It does tighten it up some. It looks pretty good.
11:19Last but not least is the footer.
11:21Let's scroll down. And here you can see the footer text is being displayed
11:25left aligned and at the full inherited font size.
11:28I'm going to style this a bit to give it a more footer-like appearance, as well
11:33as keeping it consistent with the rest of my simple design.
11:36So back in style.css, we enter in a footer selector. And let's give it a
11:44border on the top that is 2 pixels wide with a darker gray color, of 666,
11:51and make it solid.
11:57Now, let's give the text within it a smaller size, of 0.8ems.
12:06We'll align it to the center and set some padding around the entire footer. All done!
12:18Let's save the file and then double-check it.
12:21I'm going into Design view and let's just go ahead and scroll up.
12:26Everything is looking pretty basic.
12:27I have my header here, my sample page. Sidebar is looking good with all the
12:33entries well separated and my main post is over on the right. And the footer
12:39looks very much like a footer.
12:41Obviously, there's a lot more you can do with the style sheet, and you should,
12:45for any finished design.
12:47But, the idea here is to create a basic core theme that you can quickly adapt to
12:52meet the design goals of most any of your future projects.
Collapse this transcript
Establishing a theme screen shot
00:00Time to add the cherry on top of our theme: a screenshot to help identify it in WordPress.
00:05If we go into the Theme section of the Dashboard now, you can easily add that to
00:10make your theme more complete and easier to activate.
00:13WordPress needs a graphic in web-ready format--
00:17PNG, GIF, or JPEG that is--ideally, 300 pixels wide by 225 pixels tall.
00:24If you don't have a comp available, I'll show you how you can quickly create one
00:28using Dreamweaver's Live view and a graphics editor, such as Adobe Fireworks.
00:33Let's switch back to Dreamweaver where I have opened my index.php set into Live view.
00:40Now, this design is 960 pixels wide.
00:43To match the proportions of a 300 x 225 screenshot, it would need to be 720 pixels tall.
00:51In this situation, my screen is only 540 pixels tall, for recording purposes, as
00:58you can see by looking at the window size indicator on the status bar.
01:02So what I'm going to do is to grab this screen and then adjust the image in
01:06Fireworks to the proper height before I reduce it to the correct dimensions.
01:10Now it's time to fire up your screen grabber.
01:13On the Mac, you can just press Command+Shift+4;
01:16on Windows, the built-in screen grabber is called the Snipping Tool.
01:20So I'm going to go over to the Start Menu and start to type in snip. There is my
01:26Snipping tool I can click on.
01:29And I want to choose a new rectangular snip here.
01:34And there you see my crosshairs, so I'm going to grab just the top-left here,
01:39and then go down as far as I can right below the border, above the footer, and
01:44then release, and there is my screen grab.
01:47And now I will go to Edit > Copy.
01:49Now, let's head over to Fireworks so we can manipulate our screen capture.
01:53So I'm going to create a new Fireworks document and that will automatically pick
01:57up the dimensions of the image on my clipboard, which you can see is a little
02:01bit more than 960 pixels, but that's fine.
02:05So we will click on OK.
02:06And now I am going to paste that in, Ctrl+V. Let me reduce this so you can see everything.
02:13I will choose View > Fit All. And here you can see that it's off a little bit to
02:18the side, so I will bring it into the center, and let's actually move it all the
02:23way over to the left.
02:24If you look down at your Property Inspector, your X and Y should both be at 0.
02:30Now, let's go ahead and adjust the canvas size.
02:32I will click outside of my selection, make sure that the Canvas Color is set to
02:37White, and then click on Canvas Size.
02:41I'm going to set the eidth to 960 pixels and the height to 720.
02:48The next critical thing you want to do is change the Anchor. Rather than
02:52anchoring it from the center, which is the default, anchor from the top-left corner.
02:57This will make sure that the 960 pixels start all the way on the left and
03:02all the way on the top. Click OK.
03:04Now, my canvas is the right size, but it needs a little cleanup, so I'm going to
03:08go ahead and first select the image, and then I'm going to choose Edit > Crop
03:13Selected Bitmap, and I'm going to move it up a little bit, right under the
03:18borderline. That will get rid of that gray area down at the bottom.
03:22So then the next section to fit is the left-hand side, where I have a little
03:26bit of gray added here.
03:27So I'm going to go ahead and select the Marquee tool and then drag out a
03:31rectangle, and release it while I am overlapping the bottom of the image.
03:38I'll switch to my Paint Bucket tool, click Fill selection, and change the
03:44fill color to white.
03:46Place my cursor over the marqueed element, click, and now if we go up to
03:51Select > Deselect, my image is complete.
03:55There is further cleanup that you can do, and you can add in other images if you
03:58like, but it's pretty much done.
04:00So now I'm going to select my Pointer tool and then click outside of the image,
04:06and let's resize it by clicking on Image Size.
04:09We want this to be proportional, so I am going to resize the image to 300 pixels wide.
04:14And when I do, the height is automatically adjusted to 225 pixels. Click OK and
04:21there's our thumbnail.
04:22So all we have to do now is export it, and I'm going to export it as a flattened PNG.
04:27So in the Optimize panel, I'll choose PNG 8 and then choose File > Export.
04:35And we want to save this in our theme, so I am going to navigate to my site,
04:39which is within the C drive, and because I'm using WAMP, within the wamp folder,
04:46the www folder, there is my DW_WP_Themes folder.
04:51I will dive into that.
04:53And now go into wp-content/themes/ custom. And we want to give this a specific
05:01title of screenshot.png.
05:07So I'll save it. All done. Let's switch over to WordPress.
05:11And if I hit Refresh, there is my screenshot.
05:16Naturally, if you have a comp of the completed design, you create your
05:20screenshot graphic from that, but this technique provides an alternative method
05:24for those who build their sites directly in Dreamweaver, and it works well for
05:28our bare-bones custom theme.
Collapse this transcript
Testing the theme
00:00Once your basic theme is completed, it's a good idea to test what you've done
00:03already to make sure everything is working as expected.
00:07To do this, you'll need to add some dummy content in WordPress and make a
00:11few other adjustments.
00:12Let me show you some handy techniques.
00:14Let's switch over to the WordPress Dashboard, and I'm going to add a new post,
00:19by going to Posts > Add New, enter in a title: Yet another great post.
00:28Now let's switch over to lipsum.com, one of my favorite Lorem Ipsum generators.
00:35And we'll generate, let's say, three new paragraphs. And we'll copy those
00:42paragraphs back to our Dashboard, paste them in, and Publish.
00:51So now, let's head back to Dreamweaver. And if you're already in Live view, like
00:55I am, turn Live view off and then turn it on again, and here we see our new
01:00posts being included.
01:02So that all seems to be working.
01:04There is good separation between the two articles.
01:07Let's turn on Inspect mode here so that we can check that out.
01:11I'll hover over one of the paragraphs and then use the Left Arrow key to move up
01:15the DOM. So there is the div entry, there is the entire article, and here you
01:21can see that there is some yellow spacing below where it says, Posted in
01:25Uncategorized. That's the margin that we've added that separates it.
01:29Everything is looking really great there.
01:31Now, let's focus on the sidebar for a moment. I'll just click to get out of Inspect mode.
01:37The links to Recent Posts are definitely working and the Archives appear to be as well.
01:42However, we're only having one month showing, so we can't really be sure.
01:46Let's change to the dates on one of the post to check.
01:50Back to the Dashboard. And since I'm in my second post here, I'm going to go
01:54ahead and click on Edit next to the Published line, and let's go ahead and change
02:00this to the previous year.
02:03You can't do it for the future, because WordPress will not allow you to publish
02:07something that's dated in the future, so we'll click Update.
02:11Back to Dreamweaver. So now let's toggle on and off Live view again, and it
02:16looks like our archives are indeed working properly as well.
02:19Next, you may remember that the sidebar was set up with some default widgets,
02:23like the Search and various archives that we see here.
02:27Let's customize the sidebar a bit to make sure that's all working properly.
02:31Back to the Dashboard, and this time let's go to Appearance > Widgets. Let's add
02:37in a Calendar of the site posts, and I'll put that right below Search. Give it a
02:42title of Calendar, click Save.
02:46Now back to Dreamweaver and toggle Live View on and off.
02:49Well, it looks like that functionality is in place.
02:52Finally, let's see where we are with the various links built into our page.
02:56For this I'm going to go to the Live view options menu and choose Follow
03:00Links Continuously.
03:02Now, if I just go to Yet another great post and click on its title, I see the
03:06full post by itself.
03:08You'll notice that it's using the same layout, which if you remember the
03:11WordPress template hierarchy discussed in "Understanding the vasic WordPress
03:16structure" video, is exactly right.
03:19There are no additional page templates available, so everything defaults to the
03:23index.php theme layout.
03:26So your basic testing shows that everything is in order, and it also sets us
03:30up for the next task, expanding the theme to include additional content-
03:34specific pages.
Collapse this transcript
4. Adding Site Extras
Setting up the single post page
00:00When a site visitor clicks on a post title on the homepage of the blog, the
00:04expectation is that he or she will be taken to a page that shows just that post.
00:10This is referred to as a single post page, and it's the first of the additional
00:15template pages we will build in this chapter.
00:17The basis for this and most of the template pages is the theme's own index.php.
00:23The easiest way to create a single post page template is to copy the index.php
00:28file and make a few modifications.
00:31So let's start by going to our Files panel, drill down to the custom theme
00:36folder--that's found within wp-content > themes--and I'll just double-click on
00:43index.php to open it up. And then immediately I am going to choose File > Save As.
00:49And I want to make sure that I am going into the same folder. I am.
00:54And now I am going to save this as single.php.
00:57Let me close out my index.php, so I don't alter that by mistake. And now we are
01:06ready to make changes.
01:08First, since we've already drilled down into the post, we no longer need
01:13the link on the title.
01:14So I am going to remove the anchor tag that surrounds the title here.
01:18Here is my title, this h2 tag, and I am just going to select that opening
01:24anchor tag, delete that, and then delete the closing anchor tag.
01:29So now just the title will appear.
01:31Some posts can be quite long.
01:33There is no real limit to the length of a post, and long posts can be paginated
01:38by the post's author by inserting what's called a Next-Page quicktag.
01:43That's that single word, without spaces, within an HTML comment.
01:47You need to enter that into HTML mode in the WordPress dashboard.
01:52In order to show pagination, we will need to add a little bit of code here.
01:56I have this code already prepped in my single_code file that's found in the
02:01Exercise Files folder/Chapter 4/04_01.
02:06Let me open that up now. And I will grab this top snippet of code here, copy it,
02:13come back to single.php.
02:16I want this to appear right after the content.
02:19So I am going to place my cursor right after the div with the class of entry,
02:24hit Return, and then paste that in.
02:26Now, this function that's within this PHP code wp_link_pages, as you can see,
02:33works with an array and has a series of arguments.
02:36The first argument that we see here determines what text, if any, is output
02:42before the pagination.
02:44In this case, we have the word pages, followed by a colon and a space.
02:50The second argument, highlighted here, determines whether the pagination should be
02:54the word next or a number.
02:57In this case, we are going to make it a number. Okay.
03:00So next up is the postmetadata, and we have within that the tags and the
03:06categories. That's all fine.
03:08And let's keep the comments pop-up link so folks can see if there are any
03:12comments attached to it,
03:14but now let's add some new code to make it possible for the reader to leave
03:18a comment themselves. And I am going to put this code after the close of the article.
03:23So I'll position my cursor after the closing article tag, hit Return, and
03:28enter in a short bit of PHP code, calling the function comments_template.
03:39Close that out with a semicolon, and then let's close the PHP block.
03:44This function calls the built-in WordPress comments form.
03:48This too can be customized if you desire, by creating a new template file and
03:52referencing that file as an argument in the Comments Template function.
03:56For example, you might have comments function "mycomments.php."
04:03But instead of taking that route, let's add in a minimal bit of CSS to keep our
04:08comment form looking like the other pages.
04:11To get to that, I am going to first save my single.php page and then go back to
04:17the Files panel, up to where I find index.php in the site root. Open that up,
04:24switch to Design view and then Live view, click Discover, so we can get our
04:31dynamically related files.
04:32When the Script warning dialog box appears, click Yes, or you may have at this
04:37point already clicked Don't warn me again.
04:39And now we see all of our files.
04:41Let's go to style.css.
04:44So I have my cursor in the style.css side of the page, and I need to find a
04:50selector, content article.
04:52So I'm going to use Dreamweaver's power tool, Find and Replace, to do that.
04:55I will press Ctrl+F on the PC, Command+F on the Mac.
05:00I want to look in the current document and make sure I am searching the source code.
05:05In the Find box, I am going to enter-in #content article.
05:11And then click Find Next, and there's my selector, so I can close Find and Replace.
05:17Now, I want to add that selector right after the second selector in this
05:22group, widget-area aside.
05:24But because it is generated by WordPress, I don't really know what that code is.
05:29Let's use the Live Code feature in order to find that.
05:32So I am going to switch to Live Code and then go over to the Design view,
05:39hold down the Ctrl key
05:41so I can click on yet another great post, and it will follow that link.
05:47And when I do, we can see our single post page, and that's looking pretty good.
05:54And there is our comment form.
05:56And as you notice, down at the bottom of the Comment form, it's hugging the
06:01border right above the footer.
06:03So I want to add some space there, and that's why we're going to add that
06:07selector to that CSS rule.
06:10Now, I need to know what this comment form's ID is.
06:13So I am just going to put my cursor inside, and over in Live Code, I can see the
06:20form here has an ID of comment form.
06:24So I will use that selector.
06:27Let's go back to style.css.
06:29I will add a comma after widget-area aside and enter in form#commentform.
06:39Let's save that CSS page.
06:42Now, when I click back over into Design view, you can see the margin has been added.
06:47So our single page now can accommodate lengthier content, and is open to reader feedback--
06:54all in all, much better suited for displaying a single post.
Collapse this transcript
Developing a page template
00:00WordPress offers two major avenues for output: posts and pages.
00:04Whenever you create a new page, WordPress uses the page.php template in the
00:10activated theme, if it exists.
00:12For me, a custom page is very much like a single page.
00:16There's no need for a link on the title, the content may be paginated, and you
00:21often want to allow comments.
00:23So let's use the single.php page as our starting point.
00:28I'm going to open up the Files panel, and then from our custom theme folder,
00:33double-click on single.php, close the Files panel, and now choose File > Save As,
00:41and let's save this as page.php.
00:46Let me close single.php, so I don't make any changes to that by accident.
00:51Pages stand outside of the post- hierarchy, and so the sidebar is not directly
00:56useful. And what's more, designers frequently want to use the full width of the
01:00content area for page content.
01:03So the one big change I'm going to make is to remove the sidebar and expand the
01:07width of the content area.
01:09So let's scroll down to the bottom of the page, locate the PHP code block that
01:15has the get_sidebar function in it, and delete it.
01:19I'm going to now save page.php, and let's switch over to my style.css file.
01:28I'll open up the Files panel again, and double-click on style.css, close the
01:33Files panel, and let's go down to the bottom.
01:36Put my cursor at the last rule and hit Return and enter in a new rule.
01:41I'm going to use as the start of my selector a class that WordPress always
01:47inserts for any custom page, and that is .page.
01:51Now, I want to target the content area,
01:55so I'm going to enter in the ID for the content area, which is #content.
02:01Let's open up a curly brace. And I want to change the width so that it matches
02:06the width of the outer area,
02:08so I'll enter in the width property and set that to the same pixels as my outer
02:16dimension, which is 940 pixels.
02:19And now I'm going to remove the float.
02:21If you recall, the content area was previously floated to the right to allow for the sidebar.
02:27So let's enter in float and set that to none.
02:32Now, let's close off the curly brace.
02:34Let me save this style sheet. And now let's flip over to WordPress where we can
02:40create a new page and see if our new settings have taken hold.
02:44In the WordPress Dashboard, I'm going to go to Pages > Add New, enter in a new title here,
02:54and then for content, let's go to lipsum.com and pick up some Lorem Ipsum.
03:00I'm going to go with the default of five paragraphs. Generate that.
03:08Now, let's select it and I'll copy it.
03:14Back to WordPress. Paste it in.
03:16Now, before we preview this, I want to check and see if my pagination is working.
03:21If you recall, in the previous video when we developed the single page, which
03:26page.php is based on, we added the line that would show pagination controls if
03:32the Next Page quickcode was added.
03:35Let's add that now.
03:37So at the start of this paragraph here, I'm going to flip over to the HTML tab
03:42and then place my cursor right in front of the third paragraph and enter in an
03:48HTML comment with a single word nextpage, no spaces, close out the HTML comment.
03:56Let's go back to the Visual tab, and there you see an indication of the
04:01Next Page short code.
04:03Let's go ahead and click Publish. Okay.
04:06My page is published. Let's take a look at it. Click View Page and there is my
04:11new custom page without the sidebar, and my content, taking up the full width of the page.
04:17You can also see pagination is right in place.
04:20So I'll go ahead and click the second page to see the second half of my
04:25Lorem Ipsum content.
04:26I think it's a testament to WordPress' flexibility that such a major change like
04:31this can be implemented so easily.
04:33Now, your posts and pages have a completely different feel.
Collapse this transcript
Archiving posts
00:00An archive page is one that displays a collection of posts related by a
00:04particular criteria.
00:06The criteria could be a specific month, category, tag, or author, among others.
00:11In this video, I'll show you how to detect what the criteria for an archive is
00:16and how to personalize the archive page accordingly.
00:19Let's start by going to the Files panel, opening up index.php, and then saving it as archive.php.
00:35I'll close index.php. Now, I am going to open up my archive_code helper file
00:42that is found in the Exercise Files/Chapter 4/ 04_03, and I'll copy this first block of code.
00:52Switch back to archive.php. And I want to enter this right after I want to make
00:58sure that we do have some posts to work with.
01:02This is going to be a PHP if elseif type code block.
01:07So I am going to enter in the first one by pressing Ctrl+V, and let me tab this
01:14in just a little bit.
01:15So now this starts off another if block. And in this case, it's checking to see
01:20if it is a specific category, and if the archive is part of a category, it
01:25outputs this h2 code, giving it an ID of archiveTitle, which we'll see is
01:31consistent throughout all the elseif statements that we will do. And then the
01:35static text Archive for the and then a character entity, the character entity
01:418216 is for an opening smart single quote and 8217 following the PHP statement
01:48is for the smart closing quote.
01:50In the middle is a little PHP code block, single_cat_title and that will pull
01:57up whatever the category title is and paste it there, followed by the word Category.
02:04So if this post, we are in the clothing category for example, the title would
02:09read archive for the clothing category, with clothing in quotes. All right!
02:14Let's add the next one, which checks to see if there are tags.
02:18So I'll copy the lines 4 and 5 from my archive_code file, go back to archive.php,
02:27and let's paste it in inline with the php if block above.
02:35Again, let me tab this over.
02:37If it's a tag, the h2 tag has Posts Tagged, again with the opening and
02:42closing quotes, and the PHP function single_tag_title is used in order to
02:48pull in the name of the tag.
02:50The next elseif statement checks to see if the archive is date-related, and if
02:55so, we will list the actual date that it was posted on.
02:58So I am going to archive_code.php and grab this next code block, copy, paste
03:06that in, line up my h2s here. And the php function here, thetime returns the
03:14month, day, plus the ordinal suffix-- that's the TH or ST and seventh or first--
03:21as well as the year. Now there are other date-related things that we can do.
03:26What if they just click on the month?
03:28We want to see the archive for just that month.
03:30So we have an elseif statement for that as well.
03:33I will copy that from archive_code and then paste it in archive.php.
03:43Here we see that the_time function is used again returning only the month and the year.
03:51Annual archives are also possible.
03:53So we have one more date condition that we can bring in that will be appropriate
03:58for annual archives. Back to archive_ code.php, copy that code, and then paste it
04:06in below the others. Line everything up and here you see the_time function just
04:12now returns the year.
04:14Another kind of archive is author-related.
04:17So let's go get the code to check and see if the author name has been clicked on
04:22and then return a simple title.
04:24I will copy that code, tab over and paste it in, and now we are ready to enter
04:35in our last elseif clause, which is the default condition, if none of the other
04:40conditions are true. It's regarded as a general archive and the archiveTitle reflects that.
04:46So let's go to archive_code.php for one final time, and I will copy three lines of code now.
04:53The last line closes out the entire php if code block. And I will place that in
05:00the same position and then select these two lines and press Tab to move them all over.
05:06Okay. Everything is in place. Let me save the page.
05:10Now let's go back to our Files panel, open up our index.php file, go into Design
05:18view and then Live view.
05:20We will go over to our sidebar, and let me click January 2012, under the Archives.
05:27I am going to press down the Ctrl key first so that I can follow the link, and
05:33here you see Archive for January, 2012. That's as expected.
05:37It looks like we've got a little bit of a space issue here, where the title for
05:42archive is a little bit close to the post name itself.
05:46So let's go ahead and adjust that with our style.css page.
05:51I'll click the style.css up in the Related Files toolbar and then scroll down
05:56to where we have #content article, .widget-area aside, and form#commentform. And I
06:03will add another selector here.
06:05This is targeting my h2 tag with, as you'll recall, the id of archiveTitle.
06:12Save the page, and then let's click into Design view, and now some additional
06:18space has been added.
06:20Conditional functions is_category or is_tag or is_day are all really useful
06:26and can be employed in any number of page areas like sidebars or footers to
06:31display custom content depending on the type of page requested.
Collapse this transcript
Handling search results
00:00WordPress has a fairly robust search engine built-in, but you need to create a
00:04search page template to take full advantage of it.
00:07In this video, I'll show you how to display excerpts instead of a full post, and
00:12also create a custom read more link.
00:14Let's start by going to the Files panel and then drilling down to our custom
00:20theme, opening up index.php.
00:24We'll use this again as a base for our new search page.
00:29So, I'll choose File > Save As and name it search.php.
00:36Let's close index.php and start our modifications.
00:40Now the first thing I'm going to do is enter in a page title, and I'll put it in
00:46right after have_posts.
00:48We'll make this an h2 tag with an ID of pageTitle, so we can style it if we need to.
01:00And I'm going to enter in some static text here, Search Results, and then close the h2 tag.
01:09We don't really need the meta information that's found here,
01:13so I'm going to go ahead and select this div and then delete it.
01:18Next up comes the content itself. This is really the heart of the search page.
01:24Rather than showing the full post, we want to show just a small portion of it,
01:28an excerpt in other words.
01:30To do that, we change the_content function to the_excerpt function.
01:35So, I'll just select the word content and change it to excerpt. It's that simple.
01:41Now, let's make a few more changes to the page.
01:44Why don't we remove the postmetadata section?
01:47That's not really needed here either.
01:49So, let's select the div with the class postmetadata and to do that, I'm going
01:54to use the Dreamweaver technique of putting my cursor within that div and then
02:00over in the Code toolbar, click Select Parent Tag.
02:03That will select the entire div. Press Delete and that leaves us with a blank
02:08line that we can quickly erase.
02:11Now, if there are no results returned, that means that there are no
02:14Search Results found.
02:15So let me customize this Not found message just a bit, and instead of Not found,
02:21I'll make it No search results found.
02:24Okay, we're ready to check our progress,
02:26so let's go ahead and save the page and flip over to WordPress.
02:31I'm going to go visit the site and then just do a quick search.
02:37Now, I have a lot of lorem ipsum in here,
02:40so what I'm going to do is just enter in a two-letter combination.
02:44Let's look for no. Click Search.
02:47My search results are showing up.
02:50I have a no appearing in My custom page and also in Yet another great post.
02:55So the search results are looking pretty good.
02:57We're definitely getting the look we want, and with an excerpt, you see how
03:01the post is cut off after 55 words. That's the WordPress default. And an ellipsis
03:07is added to indicate additional content.
03:10However, the ellipsis is not linked,
03:13so there's no way to view the text without going and clicking on the title.
03:18Let's change the somewhat subtle ellipsis
03:21to a more visible read more link.
03:24To do that, we'll need to go back to Dreamweaver and add some code to
03:28our functions.php page.
03:30So, I'm opening up Files panel and then double-click on functions.php where we
03:37have one custom function already in place.
03:40I'll put my cursor at the end of that, and now I'm going to open up a helper file
03:44that we have available to us, functions_code.php, and it's found within the
03:50Chapter 4/04_04 folder.
03:54Here's my new function.
03:56Let me copy that. And I want to paste it within the PHP code block.
04:02So I'm going to open up the little extra lines here, leave one line of space
04:06between my two different functions, and paste that in. And then I'll just tab it
04:12over so everything is lined up.
04:15Let's save the file.
04:16Now, what this code does is it creates a new function called new_excerpt_more,
04:22which pulls in the variable post and then adds in a static ellipsis,
04:28followed by a space and a link using the post ID with the text Read more.
04:34The final part of this is the WordPress function add_filter, and what this does
04:39is it looks at the existing WordPress function excerpt_more and it replaces it
04:46with your new function, new_excerpt_more.
04:49Let's see it in action now.
04:50Now that it's saved, I can go back to the browser, hit Refresh, and there is
04:56my new Read more link.
04:58So if I click on that, it goes to the single page post and shows just
05:04that individual post.
05:06So, as you can see now, our search results are being displayed in an
05:10easy-to-read, easy-to-follow format.
05:13Of course, there's much more you can do with CSS and customizing the
05:17excerpt_more function, but this should open the door for you.
Collapse this transcript
Customizing error pages
00:00Error pages are a fact of the online life.
00:02Content is moved, URLs are typed incorrectly, bad links emerge.
00:07To ease the user experience of encountering a system-generated Page not found
00:12error, a 404 in web-speak, you can easily create a custom 404 Error page.
00:18Again, let's start with our index.php as a base.
00:21So, I'll open up Files panel, double- click on index.php, and then save it using
00:29the File > Save As command, and give it a title of 404.php.
00:36Now, we don't want to display any posts here,
00:38so I'm going to delete the bulk of this code, including all the code known as the loop.
00:44Now I scroll down a bit to make sure I've got everything. I do.
00:49I want to go ahead and get that extra line as well.
00:51So I have all the content that's within the content div. Press Delete and now
00:58let's add in some static content.
01:00I'll press Return and Tab and put in an h2 tag with the text "Sorry, but I
01:09couldn't find that page,"
01:10and then close the h2 tag and save the page.
01:14Okay, we're actually ready to give it a trial run.
01:17Now, let me go ahead and go to the site, and I'll click on one of the pages.
01:23Let's look at our Yet another great post page.
01:26Now, you'll notice up here in the address bar that this is p=4. 4 is the ID for
01:33this particular page.
01:34So, if I go in and change the p value to 99--that should be a page that I don't
01:41have anywhere--and hit Return, there is my custom 404 message.
01:47Now, obviously there's a ton more you can do on a 404 page.
01:51You could include links to common site destinations, for example. But by
01:55including even a bare-bones 404 PHP page, you keep wandering site visitors
02:01within the site itself and make it easier for them to find their way.
Collapse this transcript
Goodbye
Next steps
00:00Thanks for taking my Dreamweaver and WordPress Building Themes course.
00:04I hope you have got a lot out of it and are stoked about building your own custom themes.
00:08If you want to dive deeper into creating a WordPress site, check out my
00:13Dreamweaver and WordPress: Core Concepts course.
00:16Have a great day!
Collapse this transcript


Suggested courses to watch next:


WordPress 3: Building Child Themes (3h 11m)
Morten Rand-Hendriksen

Layouts with CSS in Dreamweaver (3h 33m)
Joseph Lowery


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,069 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked