navigate site menu

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

Dreamweaver and WordPress: Building Sites

Dreamweaver and WordPress: Building Sites

with Joseph Lowery

 


In this course, author Joseph Lowery shows how to create a robust WordPress-based site using Dreamweaver. The course lays out the essentials of planning a site, explains how to implement custom sidebars, and demonstrates building page templates. The course also explains how to integrate PHP functionality and extend the WordPress database.
Topics include:
  • Understanding development environment requirements
  • Working with existing WordPress content
  • Handling standard pages
  • Managing full posts
  • Coding a basic template
  • Adding a custom sidebar
  • Working with WordPress functions
  • Inserting PHP code in posts
  • Including a recordset
  • Outputting data
  • Linking to dynamic pages

show more

author
Joseph Lowery
subject
Web, CMS
software
Dreamweaver CS5, CS5.5, WordPress 3.x
level
Intermediate
duration
1h 42m
released
Feb 24, 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:04A WordPress site can be so much more than just a blog.
00:07First, we'll lay the groundwork so you understand what your options are in a
00:12WordPress site, and then I'll show you how to make those options a reality, one
00:16at a time, right in Dreamweaver.
00:18You'll see how to display your choice of full post or excerpt, as well as how
00:23to configure them to get the length and number you want.
00:26Then we'll cover WordPress pages so you can move beyond the basic blog format
00:31in a full multipage site.
00:34This course takes full advantage of the PHP and MySQL backbone of the WordPress
00:40application to further extend the site.
00:42You'll also see how to create new MySQL tables and incorporate the data they
00:47contain on your WordPress pages.
00:49We'll leverage Dreamweaver's built-in PHP server model support to keep the
00:54coding to a minimum.
00:55There is really a ton of functionality lying under the WordPress hood, and with
01:00Dreamweaver's help, this course will tune it up and help you rev up your sites.
Collapse this transcript
About the exercise files
00:00If you're a Premium member of the lynda.com Online Training Library, you have
00:04access 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; however, you may find it helpful to work with the
00:16supplied exercise files to practice the steps safely, and without creating your own examples.
00:21To begin using the files from the site, download them, extract them, and then
00:26store those files in a convenient location, such as your desktop.
00:30The Exercise Files folder is organized by chapter, and in every chapter it's
00:35broken down into the various videos that you'll see.
00:38Within the video chapters, there are a series of files,
00:42typically assets like CSS style sheets, images, and source code files, as well as
00:48a practice file to work with.
00:50In most of the movie folders, you'll also find a final folder, and that
00:54contains the files showing the completed lesson, which you can open and
00:58explore at your leisure.
01:00Because we're working with WordPress, which stores much of its information in a
01:03database, it's best to follow the course chapter by chapter in order to have
01:08the most recent data.
01:09However, if you would like to jump in at a certain point, I've provided an XML
01:14file for certain chapters, which you can use to bring the data into WordPress's
01:18database tables with the WordPress Import feature, found in the Dashboard,
01:23under the Tools category.
01:25You'll find the XML file in the jump-in folder.
01:29If you're a Monthly subscriber or Annual subscriber to lynda.com, you don't
01:33have access to the exercise files, but you can definitely follow along with
01:37your own assets.
Collapse this transcript
Development environment requirements
00:00Because WordPress is an application that relies on PHP and MySQL,
00:05you'll need to setup a local development environment to work with it.
00:08While going through all of the steps to create such development environment is
00:11beyond the scope of this course, I am going to lay out the requirements and give
00:16you some pointers, including one to a freely available lynda.com course.
00:21For WordPress to run, you'll need the following setup, whether on your hosted
00:25site or on your local system.
00:28You'll need a web server, like Apache or Microsoft's Internet Information
00:32Server, known as IIS.
00:34You'll also need a PHP server with a version of 5.2.4 or higher.
00:41Finally, you'll need a MySQL server, version 5.0 or higher.
00:45That will cover you if you're using any of the more recent WordPress
00:50versions 3.2 and up.
00:53If you're working on a legacy site that uses WordPress 3.1, you can use a PHP
00:59server version, 4.3 or higher, and a MySQL server version, 4.1.2 or higher.
01:05You'll still need a web server in either case.
01:09Make sure that your web site host meets these requirements before you embark on
01:13using WordPress for a site.
01:15You'll find that most do.
01:17Should you need to set up a local development environment,
01:20there are several options.
01:22You can install the components--the web server, PHP, and MySQL--separately, or you
01:28can opt to install one of the several bundled systems that are available.
01:32Here are three that work quite well.
01:35WampServer for Windows is available in both a 32- and a 64-bit version. We'll be
01:40using the 64-bit version of WAMP server during this course.
01:44For Mac OS X you can use MAMP.
01:47When you go to the MAMP homepage, you'll see that there are two versions: a
01:51standard and a pro version available. For most development work, you really only
01:56need the standard version.
01:58Finally, if you want to use one bundled server system for both Windows and Mac
02:03and you're working with a Windows 32-bit system, there is XAMPP.
02:06Now all of the bundled systems come with PHPmyAdmin installed to use as
02:12a database manager.
02:14If you're installing the components separately, I highly recommend that you also
02:19opt to include PHPmyAdmin or some similar database manager.
02:23For a detailed explanation of how you setup your local development environment,
02:28see the freely available course by David Gassner, Installing Apache MySQL and PHP,
02:34found in the lynda.com Online Training Library.
02:38Next, you'll need to setup WordPress locally.
02:41For a detailed explanation, see my course Dreamweaver and WordPress: Core Concepts.
02:46As an overview, here's what you'll need to do.
02:49First, create a database in MySQL with PHPmyAdmin or a similar application.
02:56Then copy your WordPress files to a new folder in your web root.
03:00The web root varies according to the type of server installation package.
03:05Here with WAMP, the web root will be in C:\wamp\www.
03:13With MAMP, M-A-M-P, on the Mac, it's in the MAMP Application htdocs folder.
03:19Then after you've copied those files into the web root, open up a browser and go
03:24to localhost, whatever the folder name is.
03:27There you'll see the start of the WordPress installation with the query, Should
03:31we create a configuration file?
03:33Click Yes and you're off to the races.
03:36You'll need to enter in your database name, the server name--which is
03:39often localhost, but not always--and your username and password if any for your database.
03:46The final step is to create your Dreamweaver environment.
03:50In Dreamweaver, you'll need to set up a Dreamweaver site pointing to the same
03:54folder that you've set up in your local web server root.
03:57You will also need to create a new testing server in Dreamweaver.
04:01Make sure you connect using the Local/Network settings, point to that same site
04:07folder, and on the Advanced tab select PHP MySQL as a server model.
04:12Make sure that you check the Testing server checkbox in the Server list.
04:17That can be somewhat of a gotcha, because Dreamweaver by default will select
04:22remote server for you.
04:23Make sure you make that switch to the testing server.
04:26Once your local development environment is established, you'll be able to
04:29create and develop WordPress sites, as well as work with PHP and MySQL
04:34separately in Dreamweaver.
Collapse this transcript
Working with existing WordPress content
00:00Web designers wear many hats, and from time to time they are called on to take
00:04over and expand upon an existing site.
00:07If you're working with a plain HTML site, the handover can be as simple as
00:11copying a set of files.
00:13However, if you're working with a WordPress site, life just got a bit more complicated.
00:19In this movie, I am going to show you the steps you need to take when expanding
00:23an existing WordPress site that's not your design,
00:26and along the way, show viewers who would like to use this course's exercise
00:31files how to set up your local site.
00:34This course assumes that you already have a local PHP MySQL development
00:38environment established, as discussed in the previous video.
00:42Our first step is to create a new database.
00:44I am working with WAMP server, so I'm going to go on over to WAMPSERVER, choose
00:51that, and then open up my database manager phpMyAdmin.
00:55So as I said, I want to create a new database, so let me click on Databases, and
01:02I'll enter in the name of my new database, and that will be tpa, short for the
01:08site's company, Trans Planet Airlines.
01:11Press Tab and click Create.
01:15Our database has been created. Great!
01:18Now because this is a WordPress- centric site, I am going to copy a recently
01:23downloaded copy of WordPress into my local site root.
01:28So, let me go over to Windows Explorer. Go to my Downloads.
01:32There is my downloaded expanded copy of WordPress.
01:39I'll copy that, and now I am going to go to my site root, which is C:/wamp/www.
01:47I don't have any other sites set up yet, so this will be the first one.
01:51I'll just paste that in.
01:54I'll rename WordPress to the site name, and for this course it's DW_WP_Sites.
02:07Okay, we're ready to bring up our browser to handle the WordPress installation.
02:11I'll open up a new tab and go to localhost/dw_wp_sites. This is not
02:19case sensitive, and then I'll hit Return and WordPress detects that it doesn't
02:23have a wp-config.php file.
02:27That's exactly right. That's the default condition.
02:30So, let's click on Create a Configuration File. A little informational screen
02:35comes up, telling us what it is we'll need to know to proceed.
02:38I know all those things, so let's go! All right!
02:42Database Name, we just entered that, that was tpa. User Name is root.
02:47I don't have a password set on this installation. Since it's a local
02:52development system that only I have access to, I think that's okay. And here my
02:57Database Host is localhost.
03:00That's frequently who your host is, but not always,
03:02so make sure you know the web server's database host name.
03:06All right, we'll leave the Table Prefix at wp_ and click Submit,
03:11run the install, and we are close to finished here.
03:14So I am going to put in the Site Title, and we'll use Trans Planet Airlines, my
03:20admin username, and I am going to put in a password and then confirm the
03:28password, enter my email.
03:33Now, because I'm just using this as a development site, I'm going to clear
03:36the check box that will allow my site to appear in search engines like Google and Technorati.
03:41When you install it on your remote server, obviously you want to leave that checked.
03:46Okay, let's click Install WordPress, and we're successful. Excellent. Let's Log In.
03:51I'll go to admin, enter in my password, click Log In, and here's our Dashboard.
04:00Now let me dismiss the introductory screens. Okay here is our standard
04:04WordPress installation.
04:06Now let's switch to Dreamweaver to set up our site.
04:09I'll go to Site > New Site and I am going to name this site DW WP Sites, and
04:17then locate that folder, which you'll recall is in my site root in C:/wamp/www,
04:26Your location may vary.
04:28And then double-click on the file name to make sure that I have DW_WP_Sites shown.
04:37Click Select and now let's set up a testing server.
04:42I'll click on Servers in the left column and then choose the Plus sign,
04:46which is Add New Server.
04:48We'll call this server Testing and then connect using the Local/Network option.
04:56For that we only need to enter in a server folder, which I'll do by clicking
05:00on the Folder icon, and it will default to the previously selected site, so that's perfect.
05:07Click Select and then enter in my web URL.
05:11Because this is a local server, I'll put in localhost/ and then dw_wp_sites,
05:21just the folder name.
05:22Now if I press Tab, Dreamweaver will put in the slash for you, or you can put it in yourself.
05:29One last task on this panel: click Advanced and then from the Server model
05:34list, choose PHP MySQL.
05:38Click Save and you want to be sure to deselect Remote and select Testing
05:44under the check boxes.
05:45Okay, let's save our site setup.
05:49There are our files, so all of our WordPress files installed. Excellent.
05:54Now I have a custom theme that I am going to incorporate, so I'm going to bring
05:58those into my themes folder.
06:00Let's head back to Windows Explorer, and I'll go to my Desktop to where my
06:04exercise files are, open that up, and then open up the Introduction folder.
06:12And there is only one movie folder within that, and that's the current one, 00_04.
06:17Open that up and here you see some files that we'll be accessing.
06:22The first one will be the theme, called tpa, so I am going to right-click
06:29and copy that, and now I am going to head back to my wamp installation here and select that.
06:38Themes are always stored in the wp-content folder, so if you open that up,
06:44you'll see a themes folder. Open that up and there are the two default themes,
06:49twentyeleven and twentyten. Let me go ahead and paste in my custom theme, tpa. All right!
06:55That's looking good. We've got a couple of other files to transfer.
06:59I am going to go back to Desktop/ Exercise Files/Introduction/00_04, and now
07:07let's bring in the uploads.
07:10These are some images that were used in the posts of the existing site.
07:13WordPress stores those in the wp-content/uploads folder, in a date-
07:20oriented folder structure.
07:21Let me open up uploads so you can see what I mean.
07:25Where there is a folder for every year and if I open up the year, there is a
07:29folder for every month and within that is an image and its thumbnail.
07:36So I want to copy this entire uploads folder here, and then I am going to bring
07:43it in to my site, into the wp-content folder.
07:49WordPress does not create an uploads folder until you upload the first image or file,
07:54so you won't see that there, so I'll go ahead and paste in uploads.
07:58Okay, we are finished on the Dreamweaver and file-manipulation side. Let's go
08:03back to WordPress Dashboard and activate our custom theme.
08:07You'll find the themes under Appearance > Themes, and here you see the current
08:12theme up top and two available themes down below.
08:16The one on the left is the one we want, TPA Theme, so I'll go ahead and Activate
08:22that, and let's take a look by going up to Visit Site. And yes, there is my new
08:29theme, complete with the new logo for Trans Planet Airlines. Great!
08:34All right, back to the Dashboard.
08:36There is one final task to tackle, and that's importing the data from the previous site.
08:41We've brought in the files but not the data from the posts and pages.
08:46So let's bring that in using a WordPress tool, found here under tools, called
08:52Import. And under Import, there is numerous things that you can import.
08:57We are going to import a WordPress file,
09:00so I'll click on WordPress.
09:02Now the first time you do this, it's very likely that you will need to install it.
09:06This is in a constantly evolving state, and even though it says it's not been
09:11tested with your current version, it seems to be working pretty well.
09:15So click on Install Now and then Activate Plugin & Run importer.
09:22Okay we have a XML file that we are going to bring in and if you click on Browse
09:27and then go to the Exercise Files, which are located for me on my desktop, in the
09:33Exercise Files folder, in the Introduction folder, 00_04,
09:39the XML file you are looking for is called tpa_start.
09:43All right, you can see that's an XML document, and let's click Open
09:49and then Upload file and import.
09:53Now it will give you some options regarding assigning authors and
09:56importing attachments.
09:57You can leave them at your default settings here and just click Submit.
10:01It looks like it was successful, except you'll notice that it did not bring in
10:05the media. We've already transferred that over with some files, and the fact that
10:10it failed to create a new user for admin is exactly right.
10:13Okay, so let's go to Posts.
10:16Now let's do one final test in Dreamweaver to make sure our testing server is up
10:20and firing on all cylinders.
10:22So I am going to open up the index.php file, go into Design view and then Live
10:30view, and it looks like we've got our theme working perfectly.
10:34The techniques covered in this movie are not only useful for taking over a
10:38legacy WordPress site;
10:40they can also be applied when moving a site from one web host to another.
Collapse this transcript
1. Planning Out the Site
Understanding options for a WordPress site
00:00Okay. You're working with a client who really wants to take control of their new
00:05web site's content, and you think WordPress might be the way to go.
00:08So what are your options?
00:11In this chapter, I'll give you an overview of the different possibilities for
00:14handling content in a WordPress-based site.
00:17Other than material pulled in from outside a site, there are basically two types of content:
00:23user-contributed and developer-created.
00:26We'll focus on user-contributed in this video.
00:29The best known type of user- contributed content are blog posts.
00:33A blog post is entered through the WordPress editor, or the user enters a title
00:38and they post content as well as assigning tags and categories.
00:43Once the blog post is published, additional meta information, like the author's
00:47name and date of publication, are automatically added.
00:51WordPress users can also create new pages through the dashboard's Pages interface.
00:57Like blogs, a page has a title and content.
01:01You can also assign a pager a template to provide a different look and feel or
01:05organize the pages on the site.
01:08You can create WordPress pages in the standard fashion, which is appropriate when
01:12you've got static content that needs to be updated infrequently. Or you can
01:17create your page content as a post.
01:20This works well when you want to use a different template for specific content.
01:25I'll show you how to set up this technique in the "Implementing post-driven pages"
01:29movie, found in Chapter 2.
01:31The final way that you can bring user- contributed content into a WordPress site
01:36is by setting up additional database tables and entering the information through
01:40a separate admin interface.
01:43This strategy is covered in the Chapter 5 movie, "Adding MySQL database output."
01:49As you're developing your site map, it's a good idea to decide which pages will
01:53be created using what strategy,
01:55what pages incorporate blog posts, which ones are standard custom pages, which
02:01are post-driven pages, and which include database-driven content.
Collapse this transcript
Handling standard pages
00:00Just because you're creating a WordPress- driven site, it doesn't mean that every
00:04page has to contain user-contributed content.
00:08There are often times when the client requires pages that are expressly outside
00:12the content contributor's reach.
00:14In this video, I'm going to describe a couple of ways to build such pages.
00:18The first technique takes a completely developer-created page and converts it to
00:23be theme-compatible, and it takes just a few lines of code.
00:28Let me demo the method with a dummy legal disclaimer page, one that would almost
00:33never be touched by a content contributor.
00:35So I'll go up to File > Open. And I'm going to navigate to my exercise files, in
00:43Chapter 1, folder 01_02, and open up the disclaimer.php page that you see here.
00:50Now, it says it's a PHP page, but if we take a look at the code, you can see
00:54that it's really just a standard HTML page here. That's fine.
00:59I saved it as a PHP page so that we could take advantage of the processing
01:04power of PHP in our WordPress application.
01:07So I'm going to remove all the code up top, up to, and including, the opening
01:13body tag, so I'll be left with just the content. And then also I'm going to
01:18remove the closing body and HTML tags, so we have nothing but pure content on this page.
01:24Now, let's go up to the top of the page, make a little space, and then I
01:28will put in a PHP code block, and within this code block, I'm going to
01:36put in two lines of code.
01:39The first will include a certain PHP file that will start the whole
01:43WordPress ball rolling.
01:45So type in require, open and close parentheses, and then within those, we'll put
01:51a pair of single quotes, and then the file name, which is wp-blog-header.php.
02:01Now after your last parenthesis, put a semicolon and hit Return.
02:06The require function may look familiar.
02:08Let's flip over to my index.php page and go into Code view.
02:14This is the opening page, and as you can see, we have the same basic file.
02:20Now, I'm going to save mine in the site root, so I don't really need any
02:24additional path information here.
02:28So let's enter in our second line of code, which is get_header.
02:34This function will get the header of our theme.
02:36Now, we need to put some corresponding PHP code down at the bottom to get the footer.
02:44Okay, that's actually all the code you need.
02:46I'm going to save this, as I said, in the site root, and to do that, I'll choose
02:50Save As, click Site Root from my Save As dialog box, and we'll leave it as
02:55disclaimer. Click Save. Co not click update links, click No.
03:01Let's get rid of the old version of disclaimer.
03:04Now, let's switch over to Design view and then enter into Live view, and there
03:09you can see my content now with the complete framing, including navigation,
03:16header and footer of the theme.
03:18So visually the content fits in perfectly with the rest of the WordPress theme pages.
03:23I'll go back over to index.php, enter into Design view and then Live view,
03:30and as you can see, it's identical for the header and the background, as well
03:35as the footer down below.
03:37One of the great things about this technique is should you ever update or even
03:41completely change the theme, those changes will be automatically applied.
03:46However, there is a downside to this technique.
03:49Because the pages are created outside of the WordPress database system, you
03:53can't search for them with a built-in Search function.
03:56Also, you'll need to link to any pages developed this way with absolute URLs,
04:02including the site's web address.
04:04Another way to go, and stay within the WordPress system, avoids both of these
04:09pitfalls, is to create pages that allows only WordPress users with certain roles to modify.
04:17WordPress includes five different roles.
04:20Let's flip back over to the dashboard and I can show you what those are.
04:23You can see all the roles if you choose Users > Add New, and then at the very
04:28bottom, you'll see a line for Role.
04:31And by default, new users are offered a Subscriber role, but there is also
04:37Administrator, Editor, Author, and Contributor roles.
04:42Honestly, by default, user roles in WordPress aren't extremely useful;
04:47however, they do lay a foundation for a number of killer plug-ins that can really
04:52enhance the feature.
04:54One of my favorites is called Role Scoper by Kevin Behrens.
04:59This free plug-in goes a long way towards making WordPress a more full-fledged
05:04CMS by enabling you to set access permissions for posts and pages based on role.
05:11Let me show you how it works.
05:13We'll go back to our Dashboard, go to Plugins > Add New, and in the Search
05:21Plugin field, type in Role Scoper, click Search Plugins, and it will be
05:26returned at the top of the list.
05:28I'm going to go ahead and install now.
05:31Click OK when you're asked if you sure you want to install it.
05:34The installation is pretty quick, and then click Activate Plugin.
05:39Now, keep an eye on the left-hand column and if you notice, the menu options
05:44changed significantly when the plug-in was activated.
05:47Some of the new settings as you'll find are under Users, where now we have a Role
05:52Groups option, under Restrictions, that will allow you to set restrictions on
05:57categories, navigation menus, list categories, posts and pages and an entire new
06:03category on roles, with a ton of options.
06:07For the purposes of our demo, we can leave all the settings at their default,
06:11and let's quickly create a new disclaimer page.
06:14So I'll go up to Pages > Add New, give it a title of Disclaimer, as we did
06:21before, and now I'm going to flip back to Dreamweaver and pick up that Lorem Ipsum text here.
06:27I'll copy that and back to WordPress, paste that in.
06:32Now, if you scroll down, you'll see some additional options have been added
06:38under the page editor.
06:39You can restrict the readers to this.
06:41We don't want to do that, so I'm just going to collapse that option.
06:45Contributors, we definitely want to restrict this here.
06:48So I'll choose Restrict for page. And just in case there are some sub-pages that
06:54come off of this, probably we want to restrict that as well.
06:58So we don't want anyone else to change it except administrators.
07:02So we're going to make our eligible groups here and you'll notice that these are
07:05the same roles that WordPress set up.
07:08We want only the administrators to be able to contribute to this item. All right!
07:13Contributors is done. I'll collapse that.
07:16Now Editors, I'm going to go ahead and restrict the page and sub-pages and
07:21again, make the administrator eligible.
07:24Now, we have no associates, so I can leave that alone, and let's go back up and
07:29publish our page now.
07:32Now, because I'm logged in as an administrator, if I go to Pages, I'll find my
07:38Disclaimer page here, and I can view it, I can edit it; all that's available to me.
Collapse this transcript
2. Creating Pages with WordPress Posts
Managing full posts
00:00With its default settings, WordPress shows the most recent ten posts on the homepage.
00:05If you take a look at the archives link, you will see a listing of up to ten archives.
00:11The same thing is true of search results.
00:13While it's great to have a configurable setting, showing how many posts and
00:17archives and search results you can show, I think it's a little bit of a
00:21limitation that the same setting applies across the board.
00:25In this movie, we are going to look at how you can limit the number of posts
00:29displayed on the home page without affecting the rest of your site.
00:33So I'm going to drill into my theme, tpa, and open up the index.php file, which is
00:40the main content area, switch to Code view, and I wanted to take just a moment
00:45to show you the PHP code that's responsible for outputting those posts.
00:50It starts here with the code block on line 4 and continues all the way down to
00:54line 23, the endif that you find there.
00:57This is known in WordPress speak as the loop.
01:01If there are posts, while there are posts, output the content that's found, in
01:07this case, in an article tag, including a link to title and an h2 tag, a div of
01:14meta content--basically the time it was published--the content itself, and then
01:21another div of post metadata, which show tags, categories, and comments.
01:27By default, this loop will display as many posts, up to the number available
01:32defined in the WordPress settings.
01:34Let me show you where that is.
01:35So go to Settings > Reading, and here you'll see blog pages that show at most ten posts.
01:42So if we take a look at the site now, if I click on Visit Site, there is one
01:47post, there is two posts, and you have just two there.
01:49But let's go ahead and search for IP, and here's one, two, three.
01:57So it definitely shows more than two and if I had ten results for that, it will show those.
02:02Now, let's look what happens if I change it to 1.
02:07Save Changes. Now let's go back to our site, and here we have just the one post
02:14on the homepage. That's great.
02:15But now, let's search for IP again, and we only have one search result returning.
02:21So the value that you set here is really a global setting.
02:26I'm going to restore it to 10 and then click Save Changes.
02:30Now, let's go back to Dreamweaver where we can put in a little bit of PHP code
02:35to limit your posts just on the homepage. And this code will go right after if
02:41(have_posts() ) on line 4.
02:42I am going to open up another PHP code block, and put in the
02:48function query_posts();
02:55and then within the parentheses, a pair of quotes, and we put in the property
03:00showposts= and then the number of posts that you want shown, in this case 1.
03:07Now let me close off the PHP function, save this.
03:12With the file saved, let's go back and take a look now.
03:16In our site, we now have just the most recent posts, and in our search
03:21results, I will search for the same two-letter combination, and now we've got
03:27multiple results there.
03:28You will find that the query_posts function is very helpful.
03:32You can actually use it to limit your post to a specific category or tag, as
03:37well as the number.
03:38However, you should be aware that because it alters the main loop, it could
03:43affect the rest of your page.
03:46To avoid these issues, use the wp_reset_query function after you're done.
03:51This code will go after the endif.
03:54Let me scroll up a little bit so you can see it better. Another code block,
04:01wp_reset_query, and then just an open and close parenthesis and a semicolon.
04:10Close the code block, and this page is done. So let me save it.
04:14Let's try it out in Dreamweaver.
04:16I'll open up the index.php page from the site root, go into Design view and
04:22then Live view, and now I should have just the single post here on the homepage. It looks good.
04:29Let's try our search, and I'll enter in a value and then hold down the Ctrl key
04:34while I click Search.
04:36So I get the search results that follow that link, and here's our
04:40multiple search results. Okay.
04:42So we have successfully limited our index page to showing just the most recent
04:47posts while displaying multiple entries on other WordPress pages throughout the site.
04:52Now that you've got a handle on managing full posts, you are ready to tackle
04:56partial posts, or excerpts.
Collapse this transcript
Controlling post excerpts
00:00When a client frequently updates the blog, sometimes it's better to show just
00:05a portion of several posts with an option to read the full post just a click
00:09away rather than the WordPress default, which is to show several posts in their entirety.
00:15In WordPress, these post portions are known as excerpts.
00:20Setting up your blog page to show excerpts rather than full posts is
00:24actually dirt simple,
00:26but getting WordPress to display your excerpts the way you want them to, that
00:30takes a little bit more effort.
00:32However, you can handle all the coding right in Dreamweaver.
00:36First, let's take a look at the default behavior.
00:40I have opened my site root index.php file here in Live view.
00:45If we scroll down, we see we've got one big post.
00:48Now, there's just one post here, and that's because in the previous video
00:54we used the query_posts function, which you see here on line 5, to limit the post just to 1.
01:00I'm going to expand that to 3, save the file, and now let's go back to index.php
01:09and refresh Live view.
01:13Now, when I scroll down the page, I have a number of posts.
01:17Now, I only have a couple of posts in here, so my limit of three is not reached.
01:23Now let's go back to the index.php. That's located in the Themes folder.
01:28You maybe wondering if you've got a number of different index.php files opened,
01:33how do you tell the difference from them?
01:34Well, on the coding toolbar, there is the Open Documents button.
01:38If you click that, you'll see a list of all your opened documents with complete
01:43path names and the check mark next to the one that's currently being displayed.
01:47It's a really handy feature and sometimes when I have multiple index pages
01:52opened, which you will, in WordPress, this is invaluable. Okay.
01:56So as I said, we are in the themes index right here.
02:00Now, let's switch the blog page from full post to excerpt.
02:05As I said, it couldn't be simpler.
02:07Here in the center of the page, in the div with a class of entry, we have the
02:13PHP function the_content.
02:14I'm going to change that to the_ excerpt, and save it, and voila!
02:20as the French will say. Let's go back to our index.php from the site root,
02:25refresh, and now we see just excerpts of the files.
02:30Now, this is the default presentation for excerpts.
02:33You will notice that there is a limit of a specific number of words. It's 55,
02:39in case you are wondering. And it displays an ellipsis in the square brackets at the end.
02:45Now, you might think that the ellipsis would be clickable, but it's not.
02:49To see the full post, you have to go up and click on the title.
02:52You should also realize that there's something else that's happening that may
02:56not be immediately obvious, but one result of using the excerpt function is that
03:01all HTML tags are stripped from the text.
03:04Now, let's see how we can customize the excerpt in a couple of ways.
03:08We will start by modifying the links of the excerpt.
03:11To do that, we will need to open up the function.php page that's found
03:16within our theme folder.
03:17I'll open it and then go into code.
03:22Now I already have one custom function here that registers the sidebar, so we
03:26are going to add another one.
03:28Make sure you position your cursor right within the same PHP code block. And
03:33now to help me do this, I'm going to go and open up a file from my exercise
03:38files that is called functions_code.php, and that is found in the Chapter 2, 02_02 folder.
03:50So let's open up the functions code there, and we are going to select
03:54function new_excerpt_length.
03:56Make sure you get the line that says add_filter if you're working from
04:00the exercise files.
04:02I'm going to copy that, switch back over to functions.php, and paste it in.
04:07Now, what this code is doing is it's setting up a new function called
04:12new_excerpt_length with an argument variable of length and it's returning the value of 7.
04:18That's the number of words that will be used for the excerpt. Let's try it out.
04:23So I'm going to save functions.php, go back to my index.php file, press Refresh,
04:32and there is my seven words in each excerpt. All right!
04:36Seven might be just a little bit too short,
04:40so let's head back to functions.php and change that 7 to let's say 40.
04:48Okay, so we will save that value and back to my index.php, refresh Design view,
04:55and I am not going to count them, but it looks like forty words.
04:58So the other thing we might want to change is this unclickable ellipsis here.
05:03Let's add a custom trailing phrase to replace the easily overlooked ellipses
05:08that we see here, and at the same time, make that linkable.
05:11Let's head to functions_code.php and pick up this top function along with the
05:20add_filter line, copy that, and move to our functions.php file. And then I'll
05:26add a new line return, and paste it in, select, and tab over.
05:33What this code is doing is creating a function called new_excerpt_more.
05:37It pulls in a global variable, post, and then it returns what will appear at the
05:43end of the excerpt. And what will appear at the end of the excerpt now is an
05:48ellipsis followed by a space, followed by an anchor tag with a target of the
05:54permalink of the post's ID, so you can click on Read more, which is the text
05:59you see within the anchor tag and it will go to that post.
06:02We will cover how add_filters work in a later video, but here you can see that
06:07we have the add_filter function that is filtering the default function
06:11excerpt_more with our new function new_excerpt_more.
06:15Again, save, head back to index.php and refresh Design view.
06:20So let's scroll down, and there is our new Read More link.
06:25I'm going to go ahead and press Ctrl and then click on it to follow the links.
06:32We go to our full-page post.
06:35This same type of customization is applied wherever excerpts are used, as on the
06:40search results page.
Collapse this transcript
Implementing post-driven pages
00:00Posts generally appear on a site's homepage or in a separate blog page, and are
00:05all stored separately, and can be displayed chronologically or categorically.
00:11Pages, on the other hand, can have a custom design, but there generally is only
00:15one entry, which can be easily updated.
00:18But what if your client requires a hybrid of these two types of
00:22user-contributed content?
00:24A page with a custom look and feel that can display multiple posts. I call this
00:29the post-driven page, and I'll show you how to build them in Dreamweaver and
00:33WordPress with the help of a free plug-in called List Category Posts.
00:38So let's flip over to WordPress and install that plug-in.
00:42I'll go to Plugin > Add New, and search for lists category posts that you see there.
00:51Click Search Plugins and it comes up at the top of the list.
00:55I'll click Install Now. I do indeed, so I'll click OK. And let's activate the plug-in.
01:01Now this plug-in was developed by Fernando Briano, and you can see his work at
01:07his site picandocodigo.net.
01:10It's a very flexible plug-in with a good number of parameters.
01:15As the name implies, with it you can easily create lists of posts by categories.
01:20But you can also expand those lists to show excerpts or even full post content.
01:26Here's how it works.
01:27We'll go to Posts > Categories to create a new category.
01:31I'm going to call this Working the future.
01:35Now the slug, as it explains here, is the URL-friendly version of the name, and you
01:39need to put hyphens or underscores in it;
01:42I'm going to use hyphens.
01:43That's the standard way that WordPress handles separate words.
01:47So working-the-future.
01:51We have no parent here, so let's scroll down a little bit and click Add New Category.
01:57And now you see my category in addition to the default category of Uncategorized.
02:03Now my category is defined, but before I leave this page, I need one more bit
02:07of information, and that's the ID that WordPress has assigned to that specific category.
02:13So the way you find that ID is to just hover over the name of the category and
02:18then look down in the Status Bar where you'll see the path to the file that will
02:23give you that category. And one of the URL arguments is tag_IDm and you can see
02:29that that is set to 4.
02:31So that's our ID for the category Working the future.
02:35Okay, with that in mind, we can now go in and create a new page.
02:40I'll choose Pages > Add New, and we'll enter in a future working title. And I'm
02:48going to set my template to a new template that I had created that's part of
02:52the theme called Working-the-Future.
02:55Now we're ready to bring the plug-in we installed, List Category Posts, into play.
03:00Instead of entering the standard text into the editor for this page, we'll use
03:04the plug-in's shortcode.
03:06And that is a square bracket, catlist. That's the keyword for the shortcode, short for category list of course,
03:14and then an argument of id=4, which you'll recall is the ID for the Working-the-future category.
03:23So we close this off with another square bracket
03:27and we're ready to publish this page. And let's take a look at it. And there's Working the Future;
03:35however, it's just presented as a list item.
03:38So let's head back to the Dashboard and amend our shortcode to add another argument,
03:43and that is space, content=yes.
03:48You can find all of these parameters in the documentation for this plug-in.
03:52So now I'll click on Update and View page, and there is the full list.
03:59All right! It looks pretty good.
04:03Let's head back. Let's take one more step to make my custom page easily
04:07accessible, by adding it to the menus.
04:11So I'll go down to Appearance > menus.
04:13Now I've already created a main menu here, but I'm going to select that one and
04:20then add it to the menu.
04:22And rather than have the full Working the Future title, let's go ahead and just
04:27shorten that somewhat to Working with an ellipsis.
04:31Click Save menu and now let's take a look at the site.
04:36There's Planets and there's our Working menu. All right!
04:39It's looking pretty good.
04:40You'll find that WordPress is a very flexible system, that through its core
04:45extensibility, has become even more adaptable, so that you can work with posts,
04:50pages, and even hybrids of the two.
Collapse this transcript
3. Building Page Templates
Coding a basic template
00:00The ability to create custom page templates is one of the key features that
00:04makes WordPress suitable for building web sites that are more than just a blog.
00:09A basic custom template is almost ridiculously easy to create,
00:14and in this video, we'll do just that, as well as customize the content to
00:19distinguish the custom page from our default page.
00:22Later in this chapter, you'll see how to modify the header, sidebar, and CSS of
00:27a custom page template to further set it apart.
00:30But let's start with the core page first.
00:33So now I'm going to go to my tpa folder, which is within themes, and open up index.php.
00:42We'll use that as my base, starting in Code view. And now I'll move my cursor to
00:47the top of the file, click Return, and then enter in a new PHP code block.
00:53And then within that PHP code block, enter in a PHP comment in the style of /* */.
01:03Now all I need to add within that comment is a simple name-value pair.
01:09The name, actually a name phrase, is the term Template Name, both titlecase--
01:15that's important--followed by a colon, and now the name of our template,
01:19which I'm going to call Explorers.
01:22Now let me save this as explorers.php. And I mentioned before that I was going to
01:32customize the content page a little,
01:35so what I'm going to do is remove my query_posts function, which limits the post
01:40to 3, and the corresponding wp_reset_query function.
01:47Okay, let me save explorers.php again.
01:51Now we're ready to go over to WordPress's Pages section and create a new page
01:56based on this template.
01:57From the Dashboard go to Pages > Add New.
02:02Explorers is the frequent flyers club of TPA.
02:06So I'm going to put in a Welcome page here and then just a bit of text: "Welcome
02:11to TPA Explorers, where your space miles go further."
02:22Now we want to change the template from the Default Template to Explorers, which
02:28was just dynamically added by WordPress, and click Publish.
02:34Now let's take a look at that page by Viewing Page, and there's our page, in
02:39pretty much the standard layout.
02:41You can see, in very simple text, the single entry here.
02:45So that's basically identical to the home page right now.
02:48Let's take a little time to change the contents section, starting with the
02:52title, which we no longer need to make a link.
02:55So back to Dreamweaver. On my Explorers page, I'm going to remove the anchor tag
03:02that surrounds title, both the opening and closing.
03:07Next, let's make sure that we're showing the content instead of just an excerpt,
03:14so I'll change the excerpt to the content.
03:16Now because this content could spread over multiple pages, let's add in the
03:22wp_link_pages function to add navigation for longer paginated posts.
03:28So right after the div with the class of entry and before the div with the class
03:33of postmetadata, I'm going to enter another PHP code block,
03:39and within that code block, put in a function wp_link_pages with an open and
03:47close paren, followed by a semicolon.
03:50Now this function takes an array of arguments,
03:53so we'll enter in array and then open and close paren. And the arguments
04:00within that ren, there are two,
04:03the first one sets up the text that will display before the pagination
04:08elements are shown.
04:09So that's entered as the word before, in single quotes, followed by equals,
04:16and then a greater than sign, and then again in single quotes, the word Pages.
04:24I'll put a colon there and a space.
04:27So that will be the static text that will appear before the paginated elements.
04:31Now after the closing single quote, put a comma for the second argument, and
04:37this argument determines the form of those paginated elements.
04:40Will it be the word "next" or will it be a series of numbers, like 1, 2, 3
04:45for pages 1, 2, and 3?
04:48So again, single quotes with the key phrase next_or_number and then a equals
04:56sign and greater than and opening single quote, the word Number, close the
05:03single quote, and we're done.
05:06So just to refresh, the function name is wp_link_pages.
05:12It takes an array of arguments.
05:14There are two arguments: before and next_or_number.
05:18Now finally, since most of the pages in this section are going to be
05:22policy-oriented about a specific service for our frequent space fliers, we won't
05:27need the post meta information:
05:30the tags, categories, and so on.
05:32So let's remove the div with postmetadata in it.
05:37I'll place my cursor within the div and then click the Select Parent Tag from
05:41the Coding toolbar and then press Delete to remove it entirely.
05:45Let me clean up that little extra line.
05:47Now there's one more thing I need to do before we can go preview the file,
05:52and that is to go down to the get_ sidebar function and add in the name of the
05:57sidebar that I want to insert here.
05:59So I'll put in a single quote, and when I do that, Dreamweaver CS5.5
06:04automatically puts in two single quotes for you. And then type in the ID of the
06:09sidebar, which is explorers.
06:14Okay, I'm ready to save my page with a Ctrl+S or a Command+S, and now let's
06:20preview it in the browser.
06:21So I have the same page up. I'll just hit Refresh, and you can see other
06:26information is now gone, all the postmetadata.
06:30You can also tell it's not an excerpt because there is no Read More link at the end.
06:34Of course, you can do tons more customization, but the foundation for the custom
06:39page template has now been created and you're ready to further customize the
06:44page with a unique header.
Collapse this transcript
Changing a template header
00:00While the same header across all pages in a web site is fairly common,
00:05sometimes you need to modify the header to make a particular site section really stand out.
00:10In this video, I'll show you how to change the code in the header.php file in
00:16Dreamweaver to accommodate any number of custom page templates.
00:20So let's open up header.php from our theme folder, tpa. I'll switch to Code view.
00:27As you can see, the header area has actually already been adapted once with an if-else clause.
00:33So I'll scroll down a little bit here so you can see the entire body area.
00:38This is set up now so that if there is a page template named working_future.php,
00:44as you can see on line 31, it will insert two specific images:
00:49logo_working.png and working_name.gif.
00:53Otherwise, if it's not this specific page template, show us the default images:
01:00logo.png and tpa_name.gif.
01:04Let's expand the conditional statement to check for another template,
01:08our new Explorers template.
01:10The easiest way to do that is to copy this if statement that we see here all
01:16the way down to, but not including, the closing PHP bracket.
01:20Then I'm going to just add a little bit of whitespace here so we can
01:24concentrate on the code we're working on, paste that right in the middle,
01:27and I'm going to change this else statement to an else-if statement, and we'll
01:33have it check the condition within the parentheses using a WordPress function
01:39called is_page_template,
01:41as you see employed in the if statement up above. And the name we're
01:47looking for here is the name of our template file, explorers.php.
01:53Now let's change one of the images to identify our page more clearly.
01:58We'll keep the same logo, but let's change the underlying name,
02:02so instead of spelling out Trans Planet Airlines, it says explorers.
02:07So I'll change it from tpa_ name.gif to explorers.gif.
02:13Now I happened to know that this has a different height as well,
02:16so I'm going to change the height from 37 to 48.
02:21Okay, let's get it rid of our additional spaces here, save our page, and let's preview it.
02:33So I'll move back to my index.php page and toggle in and out of Live view to make
02:39sure that we have the most recent version.
02:41There you can see my new Explorers navigation item.
02:46So I'll press the Ctrl key, Command key on the Mac, and click on that, and now
02:52you can see that our header has changed specific to this template. And we
02:56have TPA Explorers now.
02:59If I go back to any of the other pages, like Planets, you'll see different
03:05headers for those as well.
03:07You can see that the default header is showing and if I click on the default
03:11header to go back to my homepage, it's there as well.
03:16So it's only when we go into Explorers that we get the custom header here.
03:20Of course you can do whatever you need to to transform your header to work
03:25with your custom page using this conditional technique.
03:28Just add your code in the proper if or else-if clause and you're good to go.
Collapse this transcript
Adding a custom sidebar
00:00Just as you can create custom content and headers for a page template, you can
00:05also make a specific sidebar.
00:07While you could use the if-else conditional technique demonstrated in the
00:11"Changing a template header" video when it comes to sidebars, the WordPress widget
00:17functionality offers another way to go.
00:19In this video, I'll show you how to define another sidebar and display it only
00:25in a specific custom template.
00:27Then I'll show you how to fill it with content from within the
00:31WordPress dashboard.
00:32To start, we need to open up the functions.php page in order to register another sidebar.
00:39So here's my functions.php page within my theme.
00:43I'll double-click and go to code. And basically, what we're doing is exactly the
00:49same thing as we do in this very first function up here.
00:52So I'm going to copy this code here and then create another line or two and
01:00place it in the middle by pasting it in and just change a couple of values.
01:04So we're still checking to see if the register sidebar function exists and if it
01:10does, we're going to register our sidebar.
01:12Now let's change the name and ID of the sidebar.
01:16We'll make the name Explorers with an uppercase E, and the ID we'll make
01:26explores with a lowercase e. Everything else we leave the same.
01:30So I'm going to save this page.
01:33The new sidebar will pull its structure from a page called sidebar-explorers.php,
01:41which we can create from the existing sidebar.php page.
01:46So let's go over to our Files panel again, open up sidebar.php, and I'm going to
01:54save it by choosing File > Save As. And we're calling it sidebar-explorers.
02:03This is a standard WordPress convention.
02:08I'll click Save and now again, I just need to make one small change.
02:13We'll keep everything the same except I'm going to change the dynamic
02:17sidebar that we see here, from Sidebar Widgets to our ID, which is, you'll recall, Explorers.
02:26Okay, all of the code's in place. Now let me save my new page and we're ready to
02:31work on the content.
02:33So let's create one more page in WordPress so that you can see the effect we're going for.
02:38From the Dashboard, I go to Pages > Add New, and we'll give this a title of
02:43Membership Benefits. And let's quickly enter in some content.
02:51Now let's change the default template to our Explorers template and publish that page.
02:57Next we need to create some specific content that will go into our sidebar, and
03:02that content will be a custom menu.
03:04So let's go to Appearance > menus, click the plus button to add a new menu, and
03:12we'll call this Explorers.
03:16Create the menu and then scroll down a little bit here to our Pages option and
03:22check both Membership Benefits and Welcome, and add those to the menu.
03:28Now it comes in alphabetically, but you can drag and drop them to reorder. And
03:32let me save the menu.
03:34So how do we get this new menu into our sidebar?
03:37Well, we have a widget that's built-in that can do that.
03:41So we go to Appearance > Widgets, and here you see the first sidebar, which is
03:47named Sidebar Widgets.
03:48So I'll collapse that, and here you see the custom one we've just added called Explorers.
03:52I'll expand that. And now let's bring in our Custom menu widget, and we'll give it
04:00the title of Explorers. And make sure that we are selecting the menu, Explorers,
04:08which happens to be alphabetically the first one listed,
04:11so that's by default but you might want to check that. And then click Save.
04:16Okay, let's head on over to our site and there's my homepage.
04:21Now, let me click on Explorers, and there is our new Explorer page, complete
04:26with custom sidebar.
04:28We can, of course, now add any other widget we might want to our Explorers sidebar.
04:33And now you're ready to see how you can add custom CSS styling into the mix for
04:37your page templates.
Collapse this transcript
Setting template styles
00:00In the earlier videos in this chapter you've seen how to specify the content,
00:04header, and sidebar for a custom page template. But how do you style it?
00:09There are a number of techniques available, but we're going to concentrate on
00:13one based on WordPress-generated code.
00:16Let me show you what I mean by going into Live Code view.
00:20I'm going to go ahead and enable Follow Links Continuously from the Live view
00:24options dropdown. And now let me scroll over a bit and collapse this panel so
00:32we can see what's going on.
00:34I'm going to click onto the Explorers link here and once I do, you'll see in
00:41the body tag that's on line 19, one of the classes that is added is
00:46page-template-explorers-php.
00:50If we look at a standard page, like the homepage, that body class is not there.
00:59So what we want to do is use this class as our lead selector, so I'm just going
01:05to select it and then copy.
01:07Now let's go to style.css from our Related Files toolbar, and I'm going
01:16to scroll down all the way to the bottom where I have some styles for
01:19another template file.
01:21And I'm going to put it in one for Explorers.
01:24I like to add in a CSS comment here to make it easy to find these styles,
01:29so /* call this Explorers */ close that out.
01:36Now I'm going to put a period
01:38as the class indicator and then paste in my copied selector. And now I want to
01:44target the content area first.
01:47What we're going to do is we're going to float both the content area and the
01:53widget area left, and this will have the effect of moving the sidebar over to
01:58the right-hand side.
02:00So I'll further target the selector by entering in #content, and that's my main content area.
02:07Now we want to do a second selector in the same group, so I'm just going to
02:11copy the page-template-explorers- php portion of that and then paste it in.
02:18And now we want to target the sidebar, which you might recall has a class of widget-area.
02:25So I'll open a curly brace, put in by property, choose float:left. And let's
02:34close the curly brace.
02:35Now you'll notice that when my screen refreshes, there is my sidebar over on the
02:40right, but there's a little bit of an issue:
02:43the bullets of the list item are expanding beyond where I want them to.
02:47So let's go ahead and put in a margin-left property to handle that.
02:52Let's head back to our Split view. And I'm going to add in another targeted area, but I
02:57am going to continue to use this page- template-explorers-php selector. And I
03:04also want to grab widget area, because I'm going to target the unordered list
03:10within that widget area, so you might as well have them both.
03:13I'll copy that and then press Return after the closing curly brace, paste in
03:19the start of my selector, and add a ul.
03:22So let's open the curly brace, press Return, and then enter in margin-left:
03:27and let's make it 20 pixels, okay.
03:33We'll close off the curly brace.
03:34Now let's click back into Live view, and it looks like it's lining up pretty well.
03:39All right! All I need to do now is save my style sheet, and we're good to go.
03:44There's really no limit to the degree you can style a custom page template.
03:49Just remember to incorporate the dynamically added body class, which you can
03:53uncover via Dreamweaver's Live Code view.
Collapse this transcript
4. Integrating PHP Code
Working with WordPress functions
00:00So far in this course, we have mostly focused on page structure and styling.
00:04Now it's time to take a closer look at the engine that makes WordPress go, PHP.
00:10WordPress is so robust
00:11it's easy to forget that it is, top to bottom, just another PHP application.
00:17To keep it flexible and extensible, most of WordPress' power comes from an
00:22impressive series of functions.
00:23In this movie we will look at WordPress' built-in functions, as well as the main
00:28pathway for adding custom code.
00:31Let's look at an example taken from our own theme's index.php page.
00:36So I will open that up, go into Code view.
00:40Notice the very first function call here are on line two, get_header.
00:44There are numerous other built-in ones, like have_posts on line five or
00:49posts_class in the article tag on line eight, as well as the id, which is used to
00:56provide the id for that article tag.
01:00To understand more about the built-in functions, let's go to WordPress.org and do a quick search.
01:06So if I click into the Search WordPress.org box and enter in "get_header," click
01:12Go, the very first entry in the response will give us all the details that we
01:18need to know about it.
01:19And this is part of WordPress' function reference.
01:24So when I click on it you can see that the page is broken down into a General
01:28Description, Usage, Parameters, and Examples.
01:33If you're really curious about how a function is coded, go down a little bit
01:38further until you find the Source File header and there you will see the path to
01:42where the function is located in your WordPress installation.
01:46So you can look it up in Dreamweaver or click on it here.
01:50Investigating the functions is almost always rewarding.
01:53For example, when I was preparing for this course I looked up the post_class
01:58function, which is responsible for inserting pertinent classes into a tag.
02:05And under the Parameters I found a way to inject a custom class into a post tag
02:11just by passing an argument.
02:12I think that's awesome.
02:14Built-in functions are great, but they don't always do what you want them to.
02:18And it's not a good idea to customize the built-in functions, for two reasons:
02:23first, you may not be sure what other areas you are impacting, and second,
02:28because your changes will be overwritten the next time you update WordPress.
02:32However, WordPress makes it possible to add custom functionality on the theme
02:36level via the cleverly named file functions.php.
02:40If you've been following the course linearly, you've already seen us add code to
02:45the functions.php file.
02:47So let's take a closer look at how it works.
02:50I'll go to the Files panel, locate functions.php, and double-click to open it.
02:57The functions.php file in your theme is used to add or modify existing
03:02elements like sidebars.
03:04Here you can see right up top that the register_sidebar function is used twice
03:09for adding two custom sidebars.
03:12Notice on line 2 and line 14 that the first step is often to verify that the
03:17function in question exists.
03:19This is highly recommended, as it will eliminate any function-doesn't-exist
03:24errors should a file not load properly.
03:27In this case the new arguments are passed to a built-in function,
03:31register_sidebar, to create the custom sidebars.
03:35Similar functions exist for registering settings, post types, taxonomies, and
03:40widgets, among others.
03:42Now that you have seen how to explore the built-in functions and begin to use
03:45the functions.php file to customize your own, you're ready to investigate
03:50WordPress hooks for actions and filters.
Collapse this transcript
Hooking into PHP functions
00:00WordPress functions are coded to have what are referred to as hooks, so that they
00:05can be easily customized.
00:07There are two basic types of hooks: actions and filters,
00:11the latter of which we've used repeatedly in our functions.php file so far.
00:16Let's take a closer look at the code to create a filter hook first and then
00:20add an action hook.
00:22As the name suggests, a filter shifts and frequently modifies the data before
00:28it's displayed in the browser.
00:30I have opened now my functions.php file as you find within the tpa theme folder,
00:36and I am going to scroll down.
00:39Here you see two filter hooks.
00:41A filter hook has two parts: the function and the add_filter statement.
00:47The filter function is often used to define new settings for a built-in function.
00:52Let's take a look at the new_excerpt_ length function that we see starting on line 27.
00:57This is a pretty basic function that changes the length of the excerpt.
01:01By default it's set at 55.
01:04With the function new_excerpt_ length, we are changing that value to 40.
01:10Right after we define the new function, we call the add_filter to hook it into place.
01:15add_filter takes two arguments: the first argument names the WordPress function,
01:20while the second specifies the custom function that's going to filter it.
01:25The same basic concept can be applied to our second custom function
01:28new_excerpt_more, which changes the output at the end of an excerpt from being a
01:34bracketed unlinked ellipsis to, in this case, a linked phrase read more.
01:40Again, the add_filter function on line 36 names the built-in WordPress
01:45function excerpt more and then the new function that's going to filter it, new excerpt more.
01:51An action hook is different from a filter hook in that the function is triggered in
01:56response to a particular event,
01:58like a post being published for example, as opposed to changing how data is
02:03presented, which is what filter hooks do.
02:06We don't currently have any action hooks in our functions.php file, so let's add one.
02:12If you've ever looked at the code for a homepage generated by WordPress,
02:16you'll notice that WordPress by default injects a good number of meta-type
02:21code in the head section.
02:23Not all of them, in my estimation, totally necessary.
02:26Let me show you what I mean.
02:27Let's go over to our index.php from the site root. We are in Live view and I
02:33want to enter into live code now.
02:37Then here's a perfect example right up top, a wlwmanifest-type link, and then
02:44right after it is the meta tag with the generator.
02:48Well, I think I want to get rid of both of those.
02:51So let's create an action hook that will remove them.
02:55Go back to our functions.php page, and I'll go right after the last add_filter,
03:01staying within the PHP block, Tab in, and start my new function with the keyword
03:07function, and then give it a name remove_header_info, put our opening and
03:17closing curly braces, and then in the middle of it I'm going to use another
03:23WordPress function called remove_action.
03:27This takes two arguments. The first argument is the name of the WordPress
03:31function that inserts the code.
03:33In this case, it's wp_head, which we put in single quotes.
03:38Then after the closing single quote put a comma to enter your second argument.
03:44This is the code that you want to remove.
03:46All of the names like this are listed for you in the WordPress Codex.
03:51So I'm typing in wlwmanifest_link. And let's close our parentheses and put a semicolon.
04:00We are going to repeat that same line. Very similar.
04:03So remove_action(wp_head), followed by the code we want to remove, which is wp_generator.
04:17Close off our parentheses and semicolon.
04:19And I would just like filter hooks have an add_filter to activate them,
04:23we have an add action function that we need to bring in.
04:27Within its parentheses, again, there are two arguments. The first is what is the
04:33trigger for this action? And the trigger for this is a function called init, and
04:38it's encased in single quotes, followed by a comma. And the second argument
04:44is the name of the function that should be added.
04:47Of course, it's going to be our new custom function name remove_header_info.
04:51All right, we will close our parentheses and semicolon and save our page.
05:01Now let's head over to index.php. Here are the two tags that we are hoping to get rid of.
05:09Let's refresh the page and the tags are now gone.
05:14How do you know which actions or functions can act as triggers?
05:18The WordPress Codex has a great list called the Action Reference and once you
05:22go to that page, you can scroll down and you'll see just tons of available
05:27actions that you can use.
05:29The more you investigate them, the more you'll find that filter and action
05:33hooks can take you a long way towards creating just the site you and your
05:37client are looking for.
Collapse this transcript
Inserting PHP code in posts
00:00So far in this chapter, we've examined how to use custom PHP functions on the
00:05backend of WordPress.
00:06But what if you need to include PHP- generated output on the front end, in a post or page?
00:13For that degree of control you'll need to turn to one of the many plug-ins
00:17written for that purpose.
00:19In this video we will take a look at one of them that turns WordPress Visual
00:23Editor into a PHP engine.
00:25However, before we can include our PHP code, we need to write it.
00:30Dreamweaver is perfect for setting up your initial PHP code and testing it.
00:34Now I have just such a code in the exercise files and I will open it now. It's
00:40called php_example.php.
00:44And you can find it in the Chapter 4/04_03 folder.
00:49Now I have some text here that I'm going to be using in my message.
00:53I just included it in my PHP file. But the real workhorse part of this is this
00:59custom PHP function that you see here.
01:02Let me just walk you through it very quickly.
01:05It sets up a series of variables.
01:07The first is theTarget on line 11, and theTarget is set using the php mktime, or
01:15make time function. That sets the target as March 31, 2022.
01:21Today is set to PHP's basic time function.
01:25The difference between the two is set to the target minus today.
01:30Then the days, which will calculate the number of days, uses the formula that
01:34you see here, using a PHP number format function to format the number when
01:40it's returned, where we take theDiff, that is, the number of days, and divide it
01:45by the number of seconds, times the number of minutes in an hour, times the
01:49number of hours in a day.
01:51Finally, there is a print statement that outputs our texts when Venus tanning
01:57sessions will be available, and they will be available on March 31 in 2022.
02:02So it would give you an idea of how many days you have to wait before you can
02:06take advantage of that.
02:07So let's go to Design view here, and I am going to save this file in my PHP site.
02:15So I will choose File > Save As, go to the site root, and just save it there.
02:21No need to update any links.
02:24Now let's enter into Live view to make sure that our PHP code is working, and
02:28there you have it. Venus tanning sessions are a mere 3,717 days away.
02:35So we have our code.
02:36All right, looking good code-wise.
02:38Now let's switch over to WordPress and install our plug-in.
02:42So I'll go to Plugins > Add New, and we are going to search for one called exec-php,
02:49short for execute PHP.
02:56Once the search results are returned, click Install Now.
02:58OK to install it and then activate the plug-in.
03:03Now before we can use this plug-in, we need to temporarily switch off the Visual Editor.
03:09Unfortunately, you can't just use the HTML tab of the WordPress editor; you to
03:14actually disable the Visual Editor for whoever is putting in the code.
03:19That is handled through the user profile.
03:21So I will go up to the upper-right corner here and click Edit My Profile.
03:26You can also get to this through the Users option.
03:30The very first selection is Visual Editor,
03:34Disable the visual editor when writing.
03:36Let's just select that, and then I am going to scroll down to the bottom and
03:40click Update Profiles.
03:42We are ready to create our PHP-based posts.
03:48Let's get the code from Dreamweaver.
03:50I'll switch over to Code view, and I just want a copy the code that's in the body here.
03:56Now let's head back to the dashboard, add a new post, put in our title of Venus
04:03Launch Date Announced, and we will paste in the code.
04:10Now you'll notice that on the right there are no separate tabs anymore
04:14for visual HTML.
04:16That's to be expected because of course we disabled that in the profile.
04:19Now let's publish this and view the posts. Well, there it is.
04:26I've added some CSS to make it stand out, but as you can see, it's working perfectly.
04:32Once you've inserted your code, you can always go back to profile and
04:35re-enable the Visual Editor.
04:38The only time you need to disable it is when you're writing a post that is
04:41just PHP, which you can develop and test in Dreamweaver before bringing it into WordPress.
Collapse this transcript
5. Adding MySQL Database Output
Extending the WordPress database
00:00All of the posts, pages, settings and even user details for a WordPress-
00:05driven site are stored in a MySQL database, established when you first install WordPress.
00:11For the most part, this is a seamless invisible operation,
00:15so much so you may forget that you've got a fully functioning database at your disposal.
00:20In this chapter, we'll take a look at one of the ways you can leverage that
00:24database and Dreamweaver's code- writing prowess to include dynamic data from
00:30your own database tables in your WordPress pages.
00:33Let's start with creating a new table in the WordPress-created database.
00:38So, I am going to switch over to phpMyAdmin, which I've invoked from WAMP server,
00:44and I'll choose my database, tpa, and then select SQL.
00:50Now I can paste in any SQL here that I want.
00:54I had previously developed a SQL table and then exported that file.
00:59It's now stored as planets.sql, located in the Exercise Files, under Chapter 5, 05_01.
01:06So let's go into Dreamweaver and pick that up.
01:09Now you could import it, but I want to show you the code first before we bring it in.
01:17There is the code.
01:20When you're moving from one database to another it's always better to copy
01:24the code and paste it into your SQL field rather than inserting an entire
01:29file, because quite often the database names that you see here on line 19 are different.
01:35In this case, they're the same, but I've stumbled on that block many a time.
01:39So I am going to select everything, doing a Ctrl+A, Command+A on the Mac, and
01:44then copy it, and now let's head back to phpMyAdmin and do a Ctrl+V or Command+V to paste it in.
01:51Now I am going to scroll back up to the top. And just as a reminder, this is the
01:58value that you want to double-check.
02:01You'll see up here it will say "Run SQL query/queries on database" and then the
02:05name of the database.
02:06And if it's not the same, you'll need to change this value where it says database tpa.
02:13I think we're good.
02:13Let's go ahead and click Go. It's in the lower right here.
02:18After you've clicked Go, click on Structure and you'll see planets listed
02:23there as the new table.
02:24You can also go over to the little refresh here and reload your navigation frame
02:28and you'll see planets there.
02:30With the data in a new database, we're ready to create a new database
02:34connection in Dreamweaver.
02:36So back to Dreamweaver. I'll close my planets.sql file.
02:40Now I'll need to drop out of Live view in order to access the proper panel.
02:45So I'll toggle Live View off and then go to Window > Databases, and once I have
02:52that, I'll click on adding a new connection.
02:55Select MySQL Connection and then I am going to give it a name of connTPA,
03:00because we can use this connection to access all the tables that we'll need for
03:05the site, not just the single one we inserted.
03:08In the MySQL server field, enter the name of your server--
03:12in our case, it's localhost--and then the user name, which is root.
03:15You'll call that there was no MySQL password set up. And now let's choose our database.
03:21There is tpa. Click on OK.
03:25You can go ahead and click Test if you like.
03:28Dreamweaver will pick up on the fact that we haven't specified a password.
03:31In this case it's okay because we are not a production environment at the
03:35moment. And I'll click OK. And there is our new connTPA. And if I expand that
03:41and then expand Tables, we'll see our planets table, along with all of the
03:46other WordPress tables.
03:47Now also, if I expand my Files panel and scroll up to the top, you'll see the
03:55Connections folder that we have here.
03:57This is the standard way the Dreamweaver works with connections.
04:00It puts a folder in the site root.
04:03There are a couple of ways that we can use this connection in our WordPress
04:06template pages, but the standard technique isn't one of them.
04:11The quickest way I've found is to simply copy the connections folder, with the
04:15PHP file that was created within it, to our theme folder.
04:18So I am going to right-click on Connections, choose Edit > Copy, and then go down
04:27to our theme folder and right-click again, Edit > Paste.
04:32Of course, you can use the keyboard shortcuts if you want.
04:36You should see down at the bottom there for the moment, the Connections folder.
04:39If I expand it, there is our connTPA.php file.
04:44Dreamweaver has just refreshed, so it's put it back up at the top.
04:47Now that the Connections folder has been transferred, you're ready to create a
04:50recordset and apply it to a WordPress template file.
04:54I'll show you how in this chapter's video "Including a recordset."
Collapse this transcript
Including a recordset
00:00Dreamweaver offers robust support for building dynamic applications with, among others, PHP.
00:06While some may complain that the code is outdated, the truth is that it still is
00:11completely functional and very easy to work with.
00:14In this video, I'm going to show you how you can use Dreamweaver to create a
00:18basic recordset, complete with URL-driven dynamic data.
00:23Ultimately the goal in this exercise is to create what's referred to as a
00:26detail page that outputs the results of one database table record.
00:31Let's start by creating a simple database-driven page in Dreamweaver.
00:36One of the best ways to do this is to create a comp page that has the static
00:42values in it, which you'll replace with dynamic values.
00:45Now I have just such a static page found in the Exercise Files/Chapter 5/05_02,
00:52called planet_comp.php. I'll open that now.
00:57And as you can see, it's a very basic table, with a series of placeholders.
01:01We created a database connection in the first video of this chapter, "Extending
01:05the WordPress database."
01:07In order to take advantage of that connection, I am going to need to save this
01:11file into our local site root.
01:13So I'll choose File >Save As, Site Root, and then just click Save.
01:22No need to update the links.
01:25Okay, we're ready to start work on our recordset,
01:27and we do that by opening up the Bindings panel and then clicking the plus sign
01:32and choosing Recordset (Query).
01:34Now this is going to be a very basic recordset,
01:37so we can just use Dreamweaver's simple Recordset interface.
01:40I am going to call it rsPlanet, and you'll note that it defaults to the one
01:45connection that we have, conTPA.
01:48Remember, we kept a copy of that in our site root, and that's the file that
01:52Dreamweaver is now referencing.
01:55The table we're looking at is called "planets," and here are all the other tables
01:59that you also have access to.
02:01We'll accept all of the columns, because we are going to be using all of that
02:05information, but I do want to set the filter.
02:07So I am going to define this record set to filter by the id, set to the
02:13URL Parameter, also id.
02:16And since we are pulling in a single record, there's no need to do any sorting. All right!
02:21Let's click OK and save our page, and now we are ready to bind the dynamic data
02:26to its proper place in the comp.
02:29So I am just going to double-click on placeholder next to Planet here.
02:33Let me close down the Files panel a bit and expand our Bindings panel.
02:38And now I can choose planetName and then just click Insert and it will
02:43replace the selection.
02:45Let's do the same thing with the Distance from the sun placeholder, and that's
02:51planetFromSun. Click Insert.
02:53The number of Moons is listed in the database table as planetMoons. Click Insert
03:01again. And the last one is the Length of the Orbit (in Earth Years) and that is,
03:07of course, planetOrbit.
03:09Okay, so all of our placeholders have been replaced with dynamic data, but
03:13there's one more piece of the puzzle we need to bring in before the page is
03:16ready to display data.
03:18If you'll recall, we set up the recordset to filter according to a URL value
03:23for the variable id.
03:25In Dreamweaver, you can test both URL variables through the HTTP Request
03:31Settings dialog, and that's found under the Live View Options button, all the way
03:36down at the bottom. So let's open up that dialog box and then click on the
03:42plus button to add a new URL request. The name is the variable id.
03:48And now we can give it a value, any of the dynamic values that we have.
03:53Let's go ahead and start it at 1, which should return the first planet.
03:58I'll click OK and let's go into Live view.
04:03Let's save those changes, and there is the first planet, Mercury.
04:07It has no moons and it's a very short orbit. All right!
04:12You can change those values either through the HTTP Request Settings--let's do
04:18that now. And let's go to change it to four, which should give us Mars. There is Mars.
04:26You could also change it directly in the address bar.
04:29Let's see what Saturn looks like.
04:32Saturn is the sixth planet, and it has more than enough moons to go around.
04:37Okay, looks like we've got our dynamic Dreamweaver page ready, and now you're
04:42ready to integrate that into a custom template WordPress page.
Collapse this transcript
Outputting data
00:00Once you have working dynamic code in Dreamweaver, it's basically a series of
00:04straight-ahead copy-paste operations to integrate that code into a WordPress
00:09template page, with one possible exception.
00:13I will point out that exception, but let's start by bringing in a basic template.
00:18So I am going to go my Exercise Files/ Chapter 5/05_03 and open up planet.php.
00:25Let me switch to Code view, where you can see that I already have this set up as
00:32a template with the name of planet, and it's a basic page that has the
00:36WordPress loop in it.
00:37I am going to go ahead and save this, so I can put it within my theme, click
00:44Site Root in the Save As and drill down to wp_content/Themes/tpa. And we can
00:53still keep it as planet.php. No need to update the links. And let's close out
00:59that initial PHP file.
01:02So now, I'm am going to open up the planet_comp page that we worked on in the
01:06previous video, and that's located in my site root, so let me open that up. This
01:12has all of my PHP code that you'll recall we used to set up the dynamic data
01:18here that's in this table.
01:20So first I'm going to copy the PHP code and paste it from the planet_comp file
01:26to my planet.php template file.
01:30So let's go into code, go up to the top of the page, and I am going to grab
01:35everything from the top all the way down to the DOCTYPE. Make sure I get that
01:40last PHP closing bracket there, copy all of that, switch to planet.php. And
01:49normally on a PHP page, the PHP server- side code appears above everything else.
01:55With WordPress template files it has to be after the template name, so let's go
02:00past that. And because the header has some opening information as well, let's put
02:05it after the header, so I will paste that in.
02:08Now before we bring in the content, we have one more bit of structural PHP code to integrate.
02:14So I am going to go ahead and move down to the bottom of the page and switch
02:18back to planet_comp.php, and move down to the bottom of that page.
02:23And here you see the code that Dreamweaver inserts to close out the opened record set.
02:28So let's copy that final code block, head back to planet.php, and we will put it
02:34in at the bottom of the page.
02:36Okay, our structure is now in place. Let's go back and get some content.
02:40Head back to planet_comp.php, and I am going to go to Split view to make this
02:45a little bit easier. In this case I want just a table; I don't want my little header there.
02:51So I am going to put my cursor within the table. Here it is, on line 60.
02:56I want just the table. I don't want the H1 tag. So I am going to put my cursor
03:01within the table tag and then use the Select Parent Tag option to grab all of that code.
03:07You want to make sure to grab this in Code view because you are going to be
03:12pasting in the code.
03:14I'll copy it, move over to planet.php, and I want to put this after the loop ends,
03:21which is right after endif here. Paste that in and there is our table.
03:26By pasting the dynamic data below the WordPress post code, we make it possible
03:31to include any bit of static text we want, just by entering it into the WordPress page.
03:37Okay, we are ready to save our template and test it.
03:41Let's head over to WordPress and add a new page.
03:47So let's enter Planetary 411, and for now I am just going to put in some
03:52placeholder content, "Intro goes here..."
03:55I am going to set the Template to Planet and then click Publish.
04:03Okay, let's take a look at our page.
04:07Well we see now that we have our basic information, our intro, and the start of
04:13our table, but no dynamic data.
04:15Remember the recordset filter?
04:17Let's add the URL variable and value to the web address and see what happens.
04:23So I will click into the address bar and then add an ampersand, because this
04:28is another name value pair that we are adding to the URL parameters, and type in
04:33id=, let's go with 4.
04:37Looks like our record set data is fully integrated into the template page.
04:42Now you're ready to see how to link to these dynamic pages from within
04:46the WordPress site.
Collapse this transcript
Linking to dynamic pages
00:00If you've been working your way through the chapter, you've seen how we can
00:03include dynamic content in a WordPress template page.
00:07In this video I am going to show you two ways to link to that content.
00:11First, we'll take a look at the technique for creating a static link from a
00:15post or other page.
00:17We'll need one bit of information before we can code that link, the page ID.
00:21We will find that in the Dashboard's Page section.
00:25WordPress gives you a variety of options for discovering that value.
00:29So let's switch back to the Dashboard and then go to Pages.
00:33Now if you hover over any of the pages here, down in the bottom of the screen
00:37in the Status Bar, you'll see the path to the page, and it includes post= and a number.
00:45In this case, for the All Planets page, it's 78.
00:49For the Disclaimer page, it's 93. And for the Membership Benefits page, it's 130.
00:55Now if I go in to edit that page, you will also see it listed here, where the page_id=130.
01:03It's the same value, and that's the identification number for the page within
01:06the WordPress system.
01:08It's important to keep in mind that the page_id on your testing server may be
01:12different from the one on your live server,
01:15especially if like me, you create a fair amount of dummy posts in
01:19the development phase.
01:20Always verify the page_id on the live server before entering final links, when
01:25you're using this static link technique.
01:28So, how do we link to a specific page? Keep in mind that WordPress does
01:32everything off the basic homepage.
01:35So essentially you link to the homepage and add appropriate URL arguments. Let's try it out.
01:41I am going to go back to my pages.
01:43Now let's say we want to create a link to our Planetary 411, and we want to show
01:50the information from, say, Mars.
01:52So first I need to get the page_id for Planetary 411, so let me just click on it.
01:57It's a little easier to see up here in the center of the page.
02:00And we see that the page_id is 142.
02:04Okay, so let's head on over to Posts and choose Mars is Open for Business!
02:11And then we will add some text in right at the end of the first paragraph.
02:16See detailed info on Mars.
02:20Now I am going to double-click on Mars to select it and go up to my little
02:25toolbar where I can click Insert/edit link.
02:29And although by default WordPress puts in an http:// prefix, we don't need to go with that.
02:36We can just put an index.php, which is the homepage, and then a question mark
02:42for following arguments, and the key term page_id= and our page value, which was 142.
02:52Now, this will get us to the basic page, but it doesn't pass the needed argument
02:56to populate our recordset.
02:58So let's add that id=4 string, because Mars is the fourth planet in our database,
03:04as well as in our solar system.
03:06So &id=4. All right let's add that link, update the page, and let's view that post.
03:17Okay, Mars is Open for Business!
03:19There is our link. Click on the link and there is our Planetary 411 page with
03:25the information from Mars.
03:26That technique works well for static links, but how do you handle a more
03:31dynamic situation, where you have a list of links generated from the database on the fly?
03:36Dreamweaver has the answer.
03:38We'll first create a page that lists all the planets and to do that, I am going to
03:43start with my planet.php that we developed in a previous video, and I am going to
03:48save it as planets.php.
03:51So File > Save As, and let's just add an s.php there, click Save. And now we want to
04:00change the template name from planet to planets,
04:03so add an s there and now we are ready to do some work on the dynamic side.
04:07The cool thing is, once you've set up the database connection and recordset in
04:12one template, you can very easily adapt it in all the others.
04:16Let's modify a record set so that we see all the planets.
04:21So let's open up the Server Behaviors panel and double-click on the recordset.
04:26You can ignore this splat that you see there.
04:28That's because we have our PHP template name up top and typically Dreamweaver
04:33prefers to have its PHP code upfront.
04:36But it can handle it.
04:38So double-click on Recordset to open up the dialog box, and let's remove the
04:43filter by setting Filter to None so that all of the records in our database, all
04:48of the planets in other words, are returned.
04:51And let's go ahead and change the sort order so that it's sorted by
04:55planetName. Click OK.
04:59Next, let's change our data output from a table representing info about a single
05:03planet to a list of planets.
05:06So I am going to go down to find my table by going into Split view for a moment
05:12and then locate the code for the table.
05:15Use Select Parent Tag to grab it all and delete it, and now we are ready to
05:21insert our dynamic data.
05:23So let's switch to the Bindings panel and choose planetName > Insert.
05:30And there you see the PHP code for the planetName.
05:33I am going to replace my cursor right after that and then do a Shift+Return,
05:38which will bring in a line break tag.
05:41You could of course just also type in the code, but that's a little faster.
05:44Okay, so now I want to select all this new code and then one more time
05:50switch over to the Server Behaviors panel and from the dropdown list choose, Repeat Region.
06:00Now the Server Behaviors panel will not work with Code view, so you have to
06:04click in to Design view.
06:06But once you do, you'll see your dynamic information there, and we can extend
06:11the selection to include the line break by holding down Shift and pressing your right arrow once.
06:18So now all that new code is selected and we can click on Add Server Behavior and
06:24choose Repeat Region.
06:25We only have one recordset on the page. If there were multiple ones, you can
06:29choose the one you want from the list, unless of course get all of the records,
06:33in case we go over 10 planets in some future date.
06:36I will click OK and our repeat region is added.
06:40Now unfortunately, Dreamweaver is not without a little gotcha here.
06:45Several times it's happened to me that after I've changed a recordset or added
06:49a repeat region, if I go back up to the top of the code, I would find another require once here.
06:55Now while it doesn't happen all of the time, it does seem to be something that
06:59you want to keep an eye out for.
07:00We are ready to test our new template page, to make sure we're getting all of our planets.
07:06So I am going to go ahead and save it, and let's head over to WordPress, and let's
07:11create a new page. Enter a title.
07:20After entering the title, you can, if you want, also enter in some intro text--
07:24I will put in a little placeholder here--and change our template from Default to Planets.
07:35And now let's publish the page.
07:39Okay, we are ready to view it,
07:41so I will click View Page. And there is my intro text and all of our
07:46planets alphabetically.
07:51Looking pretty good. All that's left is to create a link.
07:54So let's head back to Dreamweaver. I am going to select the planetName code, and
07:59let me open up my Property Inspector and choose Browse for File.
08:05And then I am going to navigate to the index.php file, which is in our template
08:11folder, not the one on the site root. And then let's add our parameters.
08:16Click the Parameters button, and the first parameter is going to be page_id,
08:21page_id, and the value is, if you recall, 142, which was a page_id for our dynamic page.
08:31Press Tab again, twice, to go and enter another parameter.
08:35So now we'll enter id in the Name column, press Tab twice, and this time click
08:42on the lighting bolt, because we are going to add dynamic data.
08:46And from the recordset choose id. Click OK and then OK once more to close out
08:52the Parameters box, and there you can see the entire string is built up for us,
08:57and click OK one more time.
08:59Okay, let's save that page, and now let's head back to our browser. I'll click refresh.
09:06Now we have links for all of our names, and let's see if we can get to
09:10Neptune. There is Neptune.
09:13All right, it looks like everything is working perfectly.
09:17You can use this technique to build master detail page sets right within WordPress.
09:21How's that for cool?
Collapse this transcript
Goodbye
Next steps
00:00Thanks for taking my Dreamweaver and WordPress Building Sites course.
00:04I hope you found it helpful and are ready to start creating your own WordPress-
00:08based sites in Dreamweaver.
00:10If you want to dive deeper into creating a WordPress site, check out my other
00:14Dreamweaver and WordPress courses in the lynda.com Online Training library.
Collapse this transcript


Suggested courses to watch next:

Web Site Strategy and Planning (1h 37m)
Jen Kramer


CMS Fundamentals (3h 11m)
James Williamson

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