This is a discussion on "Functions?" within the PHP Forum section. This forum, and the thread "Functions? are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Functions?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
||||
|
Functions?
Me again. SOrry for all the questions, but I have to say you have all been awesome so far
WordPress uses functions for everything, like <?php wp_get_posts() ?> or whatever. On the index page, for example, this code displays the most recent post:
Would it be best to create files such as functions.php and put them all in that? Thanks, this is the last thread today, I promise! Jack
__________________
Resources Administrator
Grilling Gurus - Interviews with the Best Web Designers and Developers in the Industry Got a Question for Ryan Carson and his Web Design/Development team Carsonified? Jack Franklin - My Blog (It's a Pen in My Mouth BTW)
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
|
|
|
|
||||
|
Re: Functions?
This is to declare functions:
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Functions?
You create a function using the function keyword followed by the function name and some paranthesis. You can pretty much have the function do anything you want.
Then once you have declared the function, you call it by writing the function name and some paranthesis.
If you don't want to have to send each variable you can set an argument as optional by giving it a value inside the function declaration
That concludes a brief look at functions :mtgreen:
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
||||
|
Re: Functions?
Thanks to both of you.
Alex, I understand your first example but not this one:
__________________
Resources Administrator
Grilling Gurus - Interviews with the Best Web Designers and Developers in the Industry Got a Question for Ryan Carson and his Web Design/Development team Carsonified? Jack Franklin - My Blog (It's a Pen in My Mouth BTW)
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
|
|
||||
|
Re: Functions?
The function checks whether the value passed is true or false (0 is false, everything else is true).
If the value is true the function returns true. So the if statement will display "hi" as 1 will be evaluated to true. Not a very good example but you get the drift.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Functions?
Ok, I'm stuck again! I created my first function, which displays the most recent post:
Quote:
I'm including a file called functions.php, here it is:
I appreciate that is a huge amount of code but help would be nice Thanks, Jack
__________________
Resources Administrator
Grilling Gurus - Interviews with the Best Web Designers and Developers in the Industry Got a Question for Ryan Carson and his Web Design/Development team Carsonified? Jack Franklin - My Blog (It's a Pen in My Mouth BTW)
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
|
|
||||
|
Re: Functions?
OK, I have it narrowed down
If I replace:
The $postvariable is stored in config.php, and on the home page these are included like so:
Jack
__________________
Resources Administrator
Grilling Gurus - Interviews with the Best Web Designers and Developers in the Industry Got a Question for Ryan Carson and his Web Design/Development team Carsonified? Jack Franklin - My Blog (It's a Pen in My Mouth BTW)
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
|
|
||||
|
Re: Functions?
Any varialbles no defined in the function must be declared as global.
e.g.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Functions?
YES! Thanks Alex.
Stand by for more questions this evening though!
__________________
Resources Administrator
Grilling Gurus - Interviews with the Best Web Designers and Developers in the Industry Got a Question for Ryan Carson and his Web Design/Development team Carsonified? Jack Franklin - My Blog (It's a Pen in My Mouth BTW)
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
|
|
||||
|
Re: Functions?
I think the problem is because of the database connection, try to define a connection include file and make it global in your function, like :
__________________
Last Blog Entry: Throughout IRAN (Dec 10th, 2007)
|