So I’m interested in starting PHP. I want a base index.php with references on how to link to a header.php file ans so on. I also want to know the markup for a linked PHP file. Does it need a whole head and body tag, or does it just need the div element with
< ?php> or whatever it is.
@kgscott284 That answered none of my questions.
@nlfatkid I knew that WordPress worked on PHP, but I wanted to understand PHP so I could start, hence, why I’m asking. I could Google it, but I understand better when people on the forums tell me. Sometimes not, but most of the time.
I gotchya… I’m still kinda figuring out PHP myself… I don’t have a good grasp on it either. It feels a lot like high school algebra to me. “If, then” statements still don’t always make sense to me and it seems like the verbage of PHP doesn’t always make sense.
The thing that helped me understand PHP the most was WP. Have you looked at how a theme works?
The construction of it?
PHP works pretty damn close to it. I’ve always understand that the WP codex is a copy cat version of PHP. I just went through a huge battle with a guy on StackExchange, all over semantics of a PHP “loop” and the WP “Loop”.
I agree with @kgscott284 — you’ll be better off learning things yourself than when people give you ready-to-use code. If you want to learn a new language, learn to walk before you jog.
To link a header in your index.php file:
< ?php include 'header.php'; ?>
The contents of header.php will simply be placed where you call the include, so no additional header/footer/etc. needed.
Go get ‘em!
I assume you didn’t look or google at all…?
The link i provided in fact answers one of your questions directly, it even provides a solid example noted in the code below.
< ?php echo '
Hello World'; ?>
The main idea is you can pretty much use any standard .html page and save it as a .php, then the server will recognize it as such. You may then include files, using php code, either a include or require depending…or use php code (as in the example provided.)
I would say go through this video series and you will be ready to make real things quickly.
There is no one right answer for this, the best thing to do is familiarize yourself with PHP before decided what style you’d like to code in
I do have a relevant tip though
If you include a php file open it with < ?php but don't close it, any trailing lines or spaces after ?> may cause errors, whereas leaving it open won’t
Senff and Odd_E, I do agree w3schools is quite inaccurate–I have seen the w3fools before. However, in most cases, it provides a build-off platform-I learned the very basics there and then built off by googling other sites like this one.
I find it to be useful when I forget syntax or a function, but I do agree it is quite inaccurate.
@knittingfrenzy18 You’re right, it can be helpful when it comes to the super bare basics. If I need something fairly simple (things like the basic syntax of a CASE statement in whatever language) and I google it, I often end up on W3Schools. So yea, I use it for quick reference every now and then, but I wouldn’t recommend it to anyone as a starting course.
You must be logged in to reply to this topic.
*May or may not contain any actual "CSS" or "Tricks".