Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Once you have working dynamic code in Dreamweaver, it's basically a series of straight-ahead copy-paste operations to integrate that code into a WordPress template page, with one possible exception. I will point out that exception, but let's start by bringing in a basic template. So I am going to go my Exercise Files/ Chapter 5/05_03 and open up planet.php. Let me switch to Code view, where you can see that I already have this set up as a template with the name of planet, and it's a basic page that has the WordPress loop in it.
I am going to go ahead and save this, so I can put it within my theme, click Site Root in the Save As and drill down to wp_content/Themes/tpa. And we can still keep it as planet.php. No need to update the links. And let's close out that initial PHP file. So now, I'm am going to open up the planet_comp page that we worked on in the previous video, and that's located in my site root, so let me open that up. This has all of my PHP code that you'll recall we used to set up the dynamic data here that's in this table.
So first I'm going to copy the PHP code and paste it from the planet_comp file to my planet.php template file. So let's go into code, go up to the top of the page, and I am going to grab everything from the top all the way down to the DOCTYPE. Make sure I get that last PHP closing bracket there, copy all of that, switch to planet.php. And normally on a PHP page, the PHP server- side code appears above everything else.
With WordPress template files it has to be after the template name, so let's go past that. And because the header has some opening information as well, let's put it after the header, so I will paste that in. Now before we bring in the content, we have one more bit of structural PHP code to integrate. So I am going to go ahead and move down to the bottom of the page and switch back to planet_comp.php, and move down to the bottom of that page. And here you see the code that Dreamweaver inserts to close out the opened record set.
So let's copy that final code block, head back to planet.php, and we will put it in at the bottom of the page. Okay, our structure is now in place. Let's go back and get some content. Head back to planet_comp.php, and I am going to go to Split view to make this a little bit easier. In this case I want just a table; I don't want my little header there. So I am going to put my cursor within the table. Here it is, on line 60. I want just the table. I don't want the H1 tag. So I am going to put my cursor within the table tag and then use the Select Parent Tag option to grab all of that code.
You want to make sure to grab this in Code view because you are going to be pasting in the code. I'll copy it, move over to planet.php, and I want to put this after the loop ends, which is right after endif here. Paste that in and there is our table. By pasting the dynamic data below the WordPress post code, we make it possible to include any bit of static text we want, just by entering it into the WordPress page. Okay, we are ready to save our template and test it.
Let's head over to WordPress and add a new page. So let's enter Planetary 411, and for now I am just going to put in some placeholder content, "Intro goes here..." I am going to set the Template to Planet and then click Publish. Okay, let's take a look at our page. Well we see now that we have our basic information, our intro, and the start of our table, but no dynamic data.
Remember the recordset filter? Let's add the URL variable and value to the web address and see what happens. So I will click into the address bar and then add an ampersand, because this is another name value pair that we are adding to the URL parameters, and type in id=, let's go with 4. Looks like our record set data is fully integrated into the template page. Now you're ready to see how to link to these dynamic pages from within the WordPress site.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.