• Resolved tsalagi

    (@tsalagi)


    I’m studying the very basics of WordPress template creation and one of the templates has me scratching my head. I’m stepping through this block of code and writing an explanation of what is going on for my own benifit and then studying the WordPress codex to make sure I understand the functions used. I think the code block below has a user defined variable named after a WordPress function. It works alright but I’m just trying to make sure I don’t get the wrong idea about coding practices or maybe I’m confused about the usage.
    In this block of code lines 3 and 4 the use of $category is what I’m questioning.

    $categories_list = get_categories('hide_empty=0&orderby=name');
    $getcat = array();
    foreach($categories_list as $category){
    	$getcat[$category->cat_ID] = $item->cat_name;
    }
    $category_dropdown = array_unshift($getcat, "Choose a category:");

    I appreciate any guidance and light someone could shed on this issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • That’s normal for a foreach loop. Take line three– starts with ‘foreach’. That reads something like “for each item in the array (or object in PHP5) named $categories_list assign the value to the variable named $category and loop through using that value”. Then inside the foreach you can access $category as you would any other variable. Of course, the value changes with every iteration. I hope that makes sense.

    Thread Starter tsalagi

    (@tsalagi)

    That helps a lot. Thanks apljdi

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Template coding practice(function used as user variable)’ is closed to new replies.