Why not use something like:
$car_id = get_cat_ID('car');
Thread Starter
mhhenn
(@mhhenn)
Okay, so if I set this code on functions.php, could I later call it on the other theme files? for example when I use:
if ( post_is_in_descendant_category( $car_id ) ) {}
Or I have to declare it in every theme file?
Thanks for the quickly reply.
You should be able to put a function in your theme’s functions.php and ‘call’ that function in your other theme template files.
Thread Starter
mhhenn
(@mhhenn)
Michael I really appreciate your attention, but I have to ask you to be a little more specific. I have tried to find material on the net on how to set variables on functions, but I could not find anything. I did some try and error as well, again no luck, that is why I came to the forum.
Will that work?
function cats_ids(){
$car_id = get_cat_ID('car');
$airplaine_id = get_cat_ID('airplane');
}
and get the variable using that on the other's theme files:
cats_ids();
if ( post_is_in_descendant_category( $car_id ) ) {}
Thank you
http://www.google.com/search?q=php+pass+values+to+functions
Also can look at WordPress builtin functions (template tags) and see how that is accomplished. Further reading on that:
http://codex.wordpress.org/How_to_Pass_Tag_Parameters
Thread Starter
mhhenn
(@mhhenn)
Hi Michael. Just saw your message. Will now read the links that you sent.
Again thank you for your fast replies.
Thread Starter
mhhenn
(@mhhenn)
For the record. If you have a variable that you want to use in the other file themes you can put something like that in your functions.php:
function car_id( $car = '2320' ) { return $car; }
function airplane_id( air$plaine = '2321' ) { return $airplane; }
To call the variable in some other theme file just use:
car_id()
airplane_id()
to accesses it.
to display use:
echo car_id()
echo airplane_id()