• Resolved floyd413

    (@floyd413)


    I can’t seem to get it to work. I am trying to make a nav that goes through my subcategories, only listing the child categories of the current category.

      <?php

      $cat = get_query_var(‘cat’);
      $num = (int)$cat;
      echo $num;
      wp_list_categories(‘orderby=id&show_count=1
      &use_desc_for_title=0&hide_empty=0&child_of=$num’); ?>

    I am trying to pass the current category to the child_of parameter and it does not accept it. I echoed the $num and that is fine. The docs say child_of should be an integer. It works fine when I plain out write the number like child_of=10, but not when I use a variable. Perhaps it only accepts constants? Or am I doing something wrong. I am new to php so any help would be appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • stvwlf

    (@stvwlf)

    Hi

    wp_list_categories('orderby=id&show_count=1
    &use_desc_for_title=0&hide_empty=0&child_of=$num');

    use double quotes

    wp_list_categories("orderby=id&show_count=1
    &use_desc_for_title=0&hide_empty=0&child_of=$num");

    The difference is PHP takes what is in single quotes as literals. In double quotes it evaluates any variables and subs their values for their names. In what you did it is literally seeing child_of=$num $num being a text string which is not a valid ID thus nothing is happening

    Thread Starter floyd413

    (@floyd413)

    Thanks it works now. Just needed to learn some php.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Passing value to wp_list_categories’ is closed to new replies.