• Resolved mhhenn

    (@mhhenn)


    I use the same theme in more than one blog. Since I did some customization and they don’t have the same categories ID, every time that I update one I have to go to every single file that uses categories Id and change the id’s number.

    How do I set my own variables on fucntions.php so instead of changing the id’s in every file I just need to change it in the functions.php? Something like:

    function cats_ids(){
    $car_id = 23;
    $airplane_id = 45;

    }

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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()
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘set my own variables’ is closed to new replies.