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!
[resolved]Executing Code inside Function parameter
Moderator: General Moderators
[resolved]Executing Code inside Function parameter
Last edited by LanceEh on Mon Apr 27, 2009 11:42 am, edited 1 time in total.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Executing Code inside Function parameter
What are you trying to achieve? You shouldn't ever need to do that.
Re: Executing Code inside Function parameter
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,
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!
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'"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
Maybe:
Edit: This post was recovered from search engine cache.
Code: Select all
posts_nav_link(' - ', 'Previous Entries', 'More ' . single_cat_title() . ' Entries');
Last edited by McInfo on Tue Jun 15, 2010 12:50 pm, edited 1 time in total.
Re: Executing Code inside Function parameter
The only problem with that, is wouldn't 'More ' become one parameter, and ' Entries' another?
-
ben.artiss
- Forum Contributor
- Posts: 116
- Joined: Fri Jan 23, 2009 3:04 pm
Re: Executing Code inside Function parameter
Notice he used a full stop instead of a comma
Code: Select all
$var = 'have';
echo 'I '.$var.' nothing';
# outputs: I have nothingRe: Executing Code inside Function parameter
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.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 12:50 pm, edited 1 time in total.
Re: Executing Code inside Function parameter
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.
Thanks again.