New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

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

Dreamweaver and WordPress: Building Sites
Illustration by

Inserting PHP code in posts


From:

Dreamweaver and WordPress: Building Sites

with Joseph Lowery

Video: Inserting PHP code in posts

So far in this chapter, we've examined how to use custom PHP functions on the backend of WordPress. But what if you need to include PHP- generated output on the front end, in a post or page? For that degree of control you'll need to turn to one of the many plug-ins written for that purpose. In this video we will take a look at one of them that turns WordPress Visual Editor into a PHP engine. However, before we can include our PHP code, we need to write it. Dreamweaver is perfect for setting up your initial PHP code and testing it.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Dreamweaver and WordPress: Building Sites
1h 42m Intermediate Feb 24, 2012

Viewers: in countries Watching now:

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
Subjects:
Web CMS
Software:
Dreamweaver WordPress
Author:
Joseph Lowery

Inserting PHP code in posts

So far in this chapter, we've examined how to use custom PHP functions on the backend of WordPress. But what if you need to include PHP- generated output on the front end, in a post or page? For that degree of control you'll need to turn to one of the many plug-ins written for that purpose. In this video we will take a look at one of them that turns WordPress Visual Editor into a PHP engine. However, before we can include our PHP code, we need to write it. Dreamweaver is perfect for setting up your initial PHP code and testing it.

Now I have just such a code in the exercise files and I will open it now. It's called php_example.php. And you can find it in the Chapter 4/04_03 folder. Now I have some text here that I'm going to be using in my message. I just included it in my PHP file. But the real workhorse part of this is this custom PHP function that you see here. Let me just walk you through it very quickly.

It sets up a series of variables. The first is theTarget on line 11, and theTarget is set using the php mktime, or make time function. That sets the target as March 31, 2022. Today is set to PHP's basic time function. The difference between the two is set to the target minus today. Then the days, which will calculate the number of days, uses the formula that you see here, using a PHP number format function to format the number when it's returned, where we take theDiff, that is, the number of days, and divide it by the number of seconds, times the number of minutes in an hour, times the number of hours in a day.

Finally, there is a print statement that outputs our texts when Venus tanning sessions will be available, and they will be available on March 31 in 2022. So it would give you an idea of how many days you have to wait before you can take advantage of that. So let's go to Design view here, and I am going to save this file in my PHP site. So I will choose File > Save As, go to the site root, and just save it there. No need to update any links.

Now let's enter into Live view to make sure that our PHP code is working, and there you have it. Venus tanning sessions are a mere 3,717 days away. So we have our code. All right, looking good code-wise. Now let's switch over to WordPress and install our plug-in. So I'll go to Plugins > Add New, and we are going to search for one called exec-php, short for execute PHP.

Once the search results are returned, click Install Now. OK to install it and then activate the plug-in. Now before we can use this plug-in, we need to temporarily switch off the Visual Editor. Unfortunately, you can't just use the HTML tab of the WordPress editor; you to actually disable the Visual Editor for whoever is putting in the code. That is handled through the user profile. So I will go up to the upper-right corner here and click Edit My Profile.

You can also get to this through the Users option. The very first selection is Visual Editor, Disable the visual editor when writing. Let's just select that, and then I am going to scroll down to the bottom and click Update Profiles. We are ready to create our PHP-based posts. Let's get the code from Dreamweaver. I'll switch over to Code view, and I just want a copy the code that's in the body here. Now let's head back to the dashboard, add a new post, put in our title of Venus Launch Date Announced, and we will paste in the code.

Now you'll notice that on the right there are no separate tabs anymore for visual HTML. That's to be expected because of course we disabled that in the profile. Now let's publish this and view the posts. Well, there it is. I've added some CSS to make it stand out, but as you can see, it's working perfectly. Once you've inserted your code, you can always go back to profile and re-enable the Visual Editor. The only time you need to disable it is when you're writing a post that is just PHP, which you can develop and test in Dreamweaver before bringing it into WordPress.

There are currently no FAQs about Dreamweaver and WordPress: Building Sites.

 
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.
Upgrade now


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 Upgrade now

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: Building Sites.

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

Notes cannot be added for locked videos.

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.