KB Plugins

The best Wordpress plugins are free

Print this post

PHP Tutorial for Wordpress Users – Page 2

The very basics: What is PHP?

When you view a webpage, the server (i.e. the site you are viewing) sends a bunch of HTML to your computer. Your browser (Firefox, Safari, Internet Explorer, whatever) then turns this HTML source into the pretty stuff you see in your browser.

With pure HTML, every visitor to a website will see the same thing, no matter what. For example, if I make an HTML page with this content:

<p>Today is December 1st, 2007</p>

…everyone at my site will see this:

Today is December 1st, 2007

…even if it is not December 1st, 2007. What if you want to modify that so it always shows the current date? That’s where PHP comes in. PHP is processed by your server (i.e. by the site you are visiting). The server evaluates any PHP in the page before sending anything to your browser. So if I write this in my webpage:

<p>Today is <?php echo date('F jS, Y'); ?></p>

Then the server will change that PHP expression into the current data, then send that as HTML to your browser, which then does its part. Remember: The server processes PHP, but the browser processes HTML. PHP does not get sent to the browser, only the HTML that the PHP produces. That’s important. So important that I’ll say it again.

PHP does not get sent to the browser, only the HTML that the PHP produces.

People sometimes wonder why their theme’s index.php file looks nothing like the HTML source they see in their browser. Well, now you know why.


 

9 comments »

1
Chris adds
at 1:23 pm on December 5, 2007 #

Can this be used to display a different chunk of sidebar content depending on what page number you are on?

2
Thus saith Adam
at 6:20 pm on December 5, 2007 #

Yes, PHP can be used for that. See conditional tags.

3
gadget thinks
at 8:33 am on January 7, 2008 #

I know I need to add the PHP file to the same directory as the page containing the PHP script but which FTP directory does Wordpress store the posts in pls?

4
Thus saith Adam
at 9:44 am on January 7, 2008 #

@gadget: For general WP support, please use the WP support forums. The short answer: WP uses MySQL, not PHP, to store data.

5
KVS setty writes
at 8:50 am on January 30, 2008 #

Hello,
If the directory I am accessing from the site contains both index.php and index.htm ,What happens?

6
Thus saith Adam
at 8:55 am on January 30, 2008 #

That’s not really a PHP question. It depends on your server configuration. But why ask? Just try it and see what happens.

7
KVS setty proclaims
at 9:23 am on January 30, 2008 #

Hello,
If I use single quote to assign a string to a variable in the PHP,Can I define another variable with a double quote? I mean, can I mix and match single and double quotes according to my convince in the same PHP snippet or should I stick to only one type of delimiters throughout the snippet?
Thanks a lot for the quick reply.

8
at 9:57 am on January 30, 2008 #

Hello,
Nice tutorial! simple,easy, neat, to the point.And the best part is it inspired me to learn a new web language.Thanks a lot

9
Thus saith Adam
at 10:08 am on January 30, 2008 #

Thanks. Regarding your question about quotes, you can switch back and forth all you want. But again… why ask? Just try it and see what happens. That’s the way I learned PHP.

Leave a comment

Comment Guidelines
  • Yes, your comments will be visible to everybody. (Unless you use the private contact form.)
  • Allowed HTML: <a> <b> <blockquote> <cite> <code> <em> <i> <strong>
  • Code: Put code in `backticks` (above your "Tab" key) or it won't display well
  • Gravatars: To override the default image by your comment, use a gravatar
  • Links: If you include more than one link, your comment will go into the spam queue

Please read before commenting: Because my real job has me swamped at the moment, I am not supporting my plugins at this time. Sorry. This may last several weeks.

If you have a bug report, feature request, or other general feedback about a plugin, please leave a comment—but do not expect an immediate response. If you are requesting help, though, please check the plugin's documentation thoroughly rather than ask your question as a comment.

Thank you for your understanding.