Welcome to PHP 101, to the quickest, simplest PHP tutorial around, and the only PHP tutorial written specifically for the average WordPress user. I cover only the minimal amount of PHP necessary to competently modify your themes (and maybe even to modify plugins).
What this is
My tutorial is only a few pages long; you can read it in 20 minutes. It covers basic PHP syntax. It tells you how to assign a value to a variable, how to check that value, and how to set up a PHP if ... else ... statement. From my experience, that’s all most WordPress users need (and want) to know. If you want more details later, try PHP.net’s tutorial
.
After you have mastered the basics, you can visit one of the subpages linked below to learn several little tricks that folks ask about frequently in the wp.org support forums
:
- How do I make my first post look different from the rest?
- How do I make my posts (or anything else) have alternating colors?
Prerequisites
- Basic knowledge of HTML (HTML tutorial
) - Basic knowledge of CSS (CSS tutorial
)
Disclaimers
Most tutorials are written in inaccessible, overly technical language. I’m going to write as clearly and non-technically as possible. So please don’t complain if you notice me being a little less than precise.
Table of contents
As you click through the pagination links below, we’ll address the following topics:
- Introduction (this page)
- What is PHP? PHP vs HTML
- How do I insert PHP into a web page?
- Variables
- Conditional statements (
if,elseif, etc) - Variables in conditional statements
- Functions, and the difference between
echoandreturn - Conclusion
Ready to get started? Click on “page 2″…
20 comments »
Can this be used to display a different chunk of sidebar content depending on what page number you are on?
Yes, PHP can be used for that. See conditional tags.
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?
@gadget: For general WP support, please use the WP support forums. The short answer: WP uses MySQL, not PHP, to store data.
Hello,
If the directory I am accessing from the site contains both index.php and index.htm ,What happens?
That’s not really a PHP question. It depends on your server configuration. But why ask? Just try it and see what happens.
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.
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
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.
Hey thanks for the help I am still not getting it to work but at least I understand a bit better now. Very clean and easy to read tutorial.
What I want to see happen is if somebody click about us the header changes and so does the sidebar to match the about us content ect. I will get there this was a good start, thinking it might just be easier to copy new directories onto my server lol.
Excellent tutorial. Just wanted to say thanks for taking the time to write it! :)
Hi Adam,
Thank you for your wonderful tutorial, it’s the best and the most relevant article that I have been looking for all this while!
However, may I know how do you insert all these textboxes? It’s so cool and I hope I can know more. Any recommendations?
Ah Doe: I think you’re looking for this:
[link]
I have download a template and run it in local host by using xampp, but when i try to get it the index.php, fatal error was occurred.
Fatal error: Call to undefined function language_attributes() in C:\xampp\htdocs\gear\index.php on line 2
I have try to do with php be4, but i never try to do WP template. Do i need any install extra stuff or kind of plugin or what to make WP source code can work in PHP.
I did try something else like get_header(); is_home(); bloginfo();
The same error message will appear, really hope that you can gv me some advice. Thanks very much.
genyou, this is not a wordpress support forum.
Nice php tutorial!
thanks!!!
Hi Adam,
Thanks for looking out for me. I really appreciate it.
Was looking and looking for a quick quide on PHP with wordpress and found your pages very very helpful.
Thanks for putting this together.
hello..how can i manipulate the custom fields and make its contents appear instead of the archive list?thanks
I found your website very helpful. Thanks for posting the info.
Leave a comment