Page 1 of 1

[resolved]Executing Code inside Function parameter

Posted: Sun Apr 26, 2009 4:17 pm
by LanceEh
Is there an easy way to execute code inside a function parameter?
Do I need something like eval()?

Example:
function ('first param', echo category_title(); ,'next param');

Thanks!

Re: Executing Code inside Function parameter

Posted: Sun Apr 26, 2009 4:27 pm
by jayshields
What are you trying to achieve? You shouldn't ever need to do that.

Re: Executing Code inside Function parameter

Posted: Sun Apr 26, 2009 4:32 pm
by LanceEh
well, I should have been more specific.

Inside wordpress, there is a function to call links to previous items, and it takes text as a parameter for the link.

Right now it is,

Code: Select all

posts_nav_link(' - ','Previous Entries','More Entries'
and I wanted to add the single_cat_title() inside there so it would read

"More Blue Widgets Entries"

but all it turns into is

"More single_cat_title(); Entries"

Is there anyway around this, to execute the code inside the parameter string, (or whatever needs to be done)?

By the way, I can set it as a variable, but I still get
"More $cat Entries"

Any ideas?
Thanks a bunch!

Re: Executing Code inside Function parameter

Posted: Sun Apr 26, 2009 4:50 pm
by McInfo
Maybe:

Code: Select all

posts_nav_link(' - ', 'Previous Entries', 'More ' . single_cat_title() . ' Entries');
Edit: This post was recovered from search engine cache.

Re: Executing Code inside Function parameter

Posted: Sun Apr 26, 2009 4:58 pm
by LanceEh
The only problem with that, is wouldn't 'More ' become one parameter, and ' Entries' another?

Re: Executing Code inside Function parameter

Posted: Sun Apr 26, 2009 5:37 pm
by ben.artiss
Notice he used a full stop instead of a comma :wink:

Code: Select all

$var = 'have';
echo 'I '.$var.' nothing';
# outputs: I have nothing

Re: Executing Code inside Function parameter

Posted: Sun Apr 26, 2009 5:39 pm
by McInfo
Function arguments (and parameters) are separated by commas. There are two commas in that function call, so there are three arguments. The period/dot is the concatenation operator. It concatenates (joins) two strings together. I am assuming that the single_cat_title() function returns a string, so there are three strings ('More ', the return value of single_cat_title(), and ' Entries') that are joined together to form one string that is passed as the third argument to the posts_nav_link() function.

Edit: This post was recovered from search engine cache.

Re: Executing Code inside Function parameter

Posted: Mon Apr 27, 2009 11:41 am
by LanceEh
Thanks guys, what I did was change the single quotes to double quotes, and now the $name variable registers correctly inside the parameters.

Thanks again.