![]() |
Passing a variable to a function
I'm trying to pass a variable to a function in my wordpress skin.
Basically the function (which is a plugin) selects the latest articles from a certain category. What I want to do is define the category number when I call the function. To call the function I would write: Code:
<?php echo posts_by_category(); ?> |
As in?
PHP Code:
|
I can post the code for the function if that will help?
|
Yeah post the function
|
Code:
function posts_by_category() { |
you need to define a variable within your function such as
PHP Code:
|
I dont understand. How would I implement that into my code?
|
You're trying to pass a variable through to your function, but your function is not set up to receive any information. By including the variable within the function declaration like i showed above, you're assigning any input to that variable, which will be a valid variable now within the function with the value you assigned to it from outside the function.
So you would now take out your constant, thus your code would look like this: PHP Code:
PHP Code:
|
Thanks :) I'll try that out now.
|
No prob :)
|
I just get an error saying:
Code:
|
Did it work correctly with the constant within the function?
|
Yea :( lol
|
Try calling your function like this:
PHP Code:
|
Nope lol I tried "4" and '4' but no luck :(
|
PHP Code:
And you sure it worked correctly before? EDIT: Also, are you supposed to echo functions? I thought you just wrote it out. PHP Code:
PHP Code:
|
Just out of interest, how are you calling the function? the full line...
|
Quote:
|
Yea, you can see it working at: http://www.filmzone.org/ if you go to the bottom of the page, he list of trailers is what is generated by the function.
I want to display three lists exactly like that but from three different categories. Is there another way to do it? I'm calling the function using this: Code:
<?php echo posts_by_category(); ?> |
I didn't test this but seems your problem is on the query. Try this out:
PHP Code:
PHP Code:
|
| All times are GMT. The time now is 11:10 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0