• Resolved BradBarker

    (@bradbarker)


    Is there a way to do exactly what this code does here but have it dynamically pull the child_of value?

    Examples
    If I’m in the restaurants category or one of its child categories it should always display child categories of restaurants.
    Domain.com/category/restaurants/vietnamese/
    Domain.com/category/restaurants/

    <?php wp_list_cats('sort_column=id&optioncount=0&use_desc_for_title=0&child_of=1'); ?>

    Trying to avoid making a ton of category templates with the above code.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try:

    <?php $my_cat_id = get_query_var('cat');;
    wp_list_cats('sort_column=id&optioncount=0&use_desc_for_title=0&child_of=' . $my_cat_id ); ?>

    Thread Starter BradBarker

    (@bradbarker)

    This is very close to what i am looking for. The only issue now is that when i am on a child category of restaurants i still want restaurant categories to show up. Am i explaining this ok? LOL

    Thanks for your help!

    Thread Starter BradBarker

    (@bradbarker)

    I have a subcategory list on my categories pages.

    Example:

    Page /category/restaurants/
    Below code gives me the subcategory of my restaurants like i want

    Page /category/restaurants/vietnamese/
    Below code DOES NOT give me subcategory of restaurants.

    I want a list of restaurant subcategories on all categories pages child of restaurant

    What i have now!

    <?php $my_cat_id = get_query_var(‘cat’);;
    wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title=0&child_of=’ . $my_cat_id ); ?>

    So to complete the example. If your viewing the restaurants category and have subcategory options of American or German. You decide to click on German but after viewing the results you want to click on American but my menu currently doesn’t produce the options anymore because it is looking for subcategories of German not restaurants.

    Thread Starter BradBarker

    (@bradbarker)

    ?? Help! Is this possible esmi? Anyone?

    Try:

    <?php $this_cat = get_category( get_query_var('cat') );
    if( !$this_cat->parent )  $this_cat_id = $this_cat->term_id; // top level category
    else $this_cat_id = $this_cat->parent; // child category so use parent
    wp_list_cats('sort_column=id&optioncount=0&use_desc_for_title=0&child_of=' . $this_cat_id ); ?>
    Thread Starter BradBarker

    (@bradbarker)

    You Are a life save ESMI!!!
    Thanks a ton!

    You’re welcome. ??

    Hello esmi,

    I liked you code nd it solve my query but I need little modification in it
    I don’t want any sub categories on home page . Rest is fine

    Thanks in advance!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Need Some Help With Listing Subcategories’ is closed to new replies.