Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding dynamic data from WordPress to your web pages

From: Dreamweaver and WordPress: Core Concepts

Video: Adding dynamic data from WordPress to your web pages

Time to bring the data from WordPress right into Dreamweaver. In this lesson, we'll show you how to make a database connection, create a record set and then add the data from that record set to your Dreamweaver page. So in Dreamweaver, let's open up a previously created file to hold our dynamic data. Now this is just a standard PHP page. It's not hooked into WordPress at all. I am going to go to File > Open and then navigate to my Desktop > Exercise Files, go down to Chapter 11, and open up 11_02. I'll open that up, and it'll come in unstyled.

Adding dynamic data from WordPress to your web pages

Time to bring the data from WordPress right into Dreamweaver. In this lesson, we'll show you how to make a database connection, create a record set and then add the data from that record set to your Dreamweaver page. So in Dreamweaver, let's open up a previously created file to hold our dynamic data. Now this is just a standard PHP page. It's not hooked into WordPress at all. I am going to go to File > Open and then navigate to my Desktop > Exercise Files, go down to Chapter 11, and open up 11_02. I'll open that up, and it'll come in unstyled.

So the very first thing we are going to do is save it to the local Site Root. So choose File > Save As and then on the Save As dialog box, click Site Root and Save. Now you do not want to update the links because this is coming in with all the links intact, so click No, and there is our basic page we styled with a Exhibits header. Let me go into Live view, so you can see the full page, and it conforms to the rest of the site, not to our blog_comp.

Now the next step is to create a connection to the MySQL database used by WordPress. Now I'm going to need to open up my Database panel, but I need to drop out of Live view temporarily for that to happen. We'll click on Live view and then go to Window > Databases, and that will open up the Database panel which also has Bindings and Server Behaviors as well. We want to add a new MySQL connection. So, click on the plus sign and choose MySQL Connection. Now let's give our connection a name. I like starting with C-O-N-N, conn, and I am going to call this connExhibits.

MySQL server is localhost, my User name is Root, my Password is also root. Now that we've entered the first four fields, we can click Select. If you try to click Select before then, you won't see any databases. So click Select, and there is the databases that have been set up on my localhost. Here is roux_blog, that's the one we want, so we'll click OK. Now, it's always a good idea to test to make sure that it connects all right, and everything looks beautiful. So let's click OK once and then again to make that connection.

Now what Dreamweaver is actually doing is in the Site Root, it creates a folder called Connections and then puts a PHP page with your Connection name as the file name, so here we see connExhibits.php. Now we are ready to go to the Bindings tab. So I am going to collapse files and then click on my Bindings here, and here you can see that we have three out of the four steps already established, and we are going to complete that forth step by adding a record set, but that record set is going to employ a fairly complex bit of SQL.

So to save a little time, I have gone ahead and created that for you. I am going to open up that file from the exercise files again. So go over to File > Open, and let's head back to our Desktop > Exercise Files in Chapter 11, again 11_02, and this time open up recordset.sql. So you may look at this, and if you're not that familiar with SQL and think of it as a very complex SQL statement, it's actually relatively straightforward. Let me walk through it a little bit so you understand it better. But basically, what we are doing here is selecting a set of records, hence the name recordset.

So we want the recordset to be distinct so that there are no duplicates, and that's the keyword distinct here, and we are going to bring in the WordPress post title as well as the content. So just those two items, the title and the content, and we're bringing those in from a table called wp_posts which is pretty much self- explanatory, and then also the wp_term_relationships table is being used. Now that's the table that monitors the categories among other things and its relationship to the various posts.

So after that connection is made here in the WHERE statement, we want to make sure that we are filtering on a field called post_status listed here, and that is set to private and then also another field in the wp_term_relationships table called term_taxonomy_id, and that's going to be set to a specific value. Now just because I use this SQL statement a lot, I have this set up with a couple of question marks, but we want to replace those question marks with a certain value, and what is that value? Well, it's going to be the category number that we saw earlier, which as you might recall for me is 10.

The order of the records that is returned, which is the next and final line on the SQL statement, is set to showing the newest one first or in other words the dates descend. So I am going to select the SQL statement, copy it, and head back to my exhibits.php file where we are ready to create the recordset. So I'm in the Bindings panel, I'll choose the plus sign, and then select Recordset (Query). Now what you see on the screen here is what's known as the simple version of the Recordset. There are two different views. We want to switch to the Advanced view.

Now if you have done some database work before, and you have established another recordset where you did use Advanced view, that will come up automatically. So, I am going to call this rsExhibits. And I want to make sure that my connection is set to connExhibits, and since that's our only connection, that's what's going to happen. Now after I press Tab, it goes to the SQL field, and I can delete what's selected and paste in with a Command+V, MySQL statement. Now let's go ahead and test this by clicking the Test button here. And here you see the one record that we have, Student Exhibit, and a little bit of content there.

That's good. So click OK once and then one more time to close the Recordset. All right. We are actually ready to bring the content onto the page. So I am going to put my cursor where I want it to appear, and you have to do this in Design view, you can't do it in Live view, and I am just going to put it right after the paragraph, and I am going to expand my Recordset that you see here--let me bring the Field name over a little bit so you can see all the information-- and here you see the two fields that we brought in, post_title and post_content. We are going to insert post_title first.

So you can drag and drop it onto the screen, or if you've already positioned your cursor as I have where you wanted to go, you can select what you want and then click Insert. Now, that will come in as a standard paragraph, as you can see down here in the Tag Selector at the bottom of the screen. Let me open up my Property Inspector, and I am going to change that Format to an h2 tag. After that, I'll hit Return so after the title we'll put in the content. Now, this time I am just going to go ahead and drag that content in to show you the alternative way that you can work with this, and each time I do, you see that it lists in curly braces, and it slightly highlighted the Recordset name rsExhibits and then dot and whatever the field name is.

Okay, so there is our two bits of content. Let's save the page, and now I am going to go into Live view, and Live view works not only for CSS and PHP, but it also works for MySQL. So we can see that brings in the dynamic content, and we do have a little bit of work to do here, but that's good because it shows that up. So I am going to go ahead and create a new CSS rule in main.css. Let's go down a little bit here, and I'll put it towards the bottom, right above the @media statement for my phone.

So this will be one for mainContent and an unordered list, and that will handle any unordered lists that are encountered here. I am just going to set the margin, 0 at the top, 0 on the right, do 15 pixels on the bottom, and 20 pixels on the left. So I'll save that and then head back to Design view, and it's much better. But at the moment, this dynamic page would only show one event. So if I toggle off Live view, you can see that I just have these two bits of code here, moreover, the event that it would always show would be the most current.

Now that might work in some situations, that might be in fact exactly what you want to do, but let's say we want it to show multiple events. So what do we have to do? Well, what we need to do is wrap whatever it is we want to repeat in what's known as a Repeat Region server behavior. So I am going to add one more bit of content, and that's a horizontal rule here, and I'll put that right after my content so that we have a little bit of separation between the two. I am just going to go right to the Source Code and put my cursor there.

So instead of a paragraph tag here, I'll make this an hr tag, okay. So, we'll save that and then head back to Design view, and you can see my new horizontal rule there. So now we are ready to add a Dreamweaver server behavior. I am actually going to go back into the Split view as I found it's actually easier a lot of times to select exactly the content that you want. And in this case, what I want are these three code lines here, the h2 which has the PHP code for showing the title, the paragraph tag which has the PHP code for showing post_content, and then my horizontal rule.

With that selected, let's go over to our Server Behaviors panel where you can see certain Server Behaviors have already been added. There is our Recordset, and these are the two items that we inserted into the text. So, I'll click the Add button and choose the second option which is Repeat Region. Now when it comes up, you'll show a list of your recordsets. If we had more than one defined, it would be available to us from the list here, but we only have rsExhibits. So that's pre-selected for us. And there is two options. You can choose to show a finite number of records at a time, and it's definable, it can be 10 as the default setting is or 5 or 3, or if you want to show all the records as we do, you can choose All Records.

So then click OK and Dreamweaver will add in the necessary code, it's a PHP do-while loop. And let's go back to Design view now, and we'll turn on Live view, click Save and right now what you'll see is basic code, so we still have just one bit of content here, so you're only going to see one record. Let's go back to WordPress, and I'm going to add a new post that I'll call Spotlight Exhibit, and we have some sample content as well. And again, I am going to add in a few bullet points. Okay, we are going to do those same two things that we did before when we changed the visibility to private, so let's go over to Edit, next to Visibility, change that to Private, and click OK, and we already have our Exhibit category set up, so I'll click Exhibits and Update.

Let's head back to Dreamweaver, and I am just going to refresh the page, and now we have two exhibits listed on our Exhibit page, Spotlight Exhibit, and Student Exhibit. There is the separator and everything looks in proper date order that we had set up. So, this is really just the start of what you can do with data from a WordPress-driven database. All of the other Dreamweaver Server Behaviors are at your disposal as well.

Show transcript

This video is part of

Image for Dreamweaver and WordPress: Core Concepts
Dreamweaver and WordPress: Core Concepts

55 video lessons · 51730 viewers

Joseph Lowery
Author

 
Expand all | Collapse all
  1. 4m 7s
    1. Welcome
      58s
    2. Using the exercise files
      1m 54s
    3. A word about updates
      1m 15s
  2. 15m 28s
    1. Overview
      1m 51s
    2. Creating the database and the initial site
      3m 45s
    3. Configuring WordPress
      5m 54s
    4. Establishing a Dreamweaver site
      3m 58s
  3. 20m 18s
    1. Accessing dynamically related files
      4m 12s
    2. Filtering files
      4m 20s
    3. Following links
      4m 15s
    4. Employing Live Code
      2m 54s
    5. Enabling site-specific code hinting
      4m 37s
  4. 21m 8s
    1. Adding blog posts
      4m 55s
    2. Editing blog posts
      3m 20s
    3. Adding new pages
      2m 59s
    4. Including images
      6m 59s
    5. Adding videos to posts
      2m 55s
  5. 18m 12s
    1. Understanding WordPress structure
      3m 52s
    2. Activating a theme
      7m 21s
    3. Setting up a child theme
      6m 59s
  6. 1h 29m
    1. Updating the page structure and the background
      12m 53s
    2. Working with web fonts
      4m 3s
    3. Styling a header
      11m 48s
    4. Adding header functions
      7m 40s
    5. Setting up content columns
      10m 9s
    6. Changing the main content
      5m 17s
    7. Managing the content code
      4m 48s
    8. Customizing the sidebar
      10m 32s
    9. Styling search
      7m 8s
    10. Working with search text
      5m 49s
    11. Integrating the footer
      9m 40s
  7. 27m 18s
    1. Setting up media queries
      6m 12s
    2. Customizing for tablets
      12m 19s
    3. Building smartphone layouts
      8m 47s
  8. 23m 28s
    1. Working with categories and posts
      5m 31s
    2. Developing category-driven pages
      11m 22s
    3. Changing headers by category
      6m 35s
  9. 36m 32s
    1. Adding Spry accordion panels
      17m 44s
    2. Working with Spry form validation
      11m 56s
    3. Integrating jQuery functionality
      6m 52s
  10. 11m 7s
    1. Understanding WordPress plugins
      6m 20s
    2. Styling plugin output
      4m 47s
  11. 25m 44s
    1. Customizing the Dashboard
      6m 52s
    2. Working with WordPress functions
      8m 7s
    3. Including administration interactivity
      10m 45s
  12. 13m 10s
    1. Setting up the data in WordPress
      2m 17s
    2. Adding dynamic data from WordPress to your web pages
      10m 53s
  13. 11m 38s
    1. Modifying general settings
      4m 12s
    2. Setting up users
      3m 11s
    3. Restricting access to specific WordPress pages
      4m 15s
  14. 26m 38s
    1. Exporting and importing WordPress files
      7m 9s
    2. Backing up and restoring the database
      8m 10s
    3. Transferring files
      6m 3s
    4. Testing and fine-tuning
      5m 16s
  15. 18s
    1. Next steps
      18s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Dreamweaver and WordPress: Core Concepts.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

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.

Sign up and receive emails about lynda.com and our online training library:

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

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.