Forums

[resolved] Displaying categories conditionally (2 posts)

  1. liberty50
    Member
    Posted 2 years ago #

    Hi guys,

    I do not have a php background, but have been working through some custom functions on a new blog. Today I ran into a stumbling block I can't seem to overcome. I'm hoping someone here might offer some advice. Here is my goal.

    On category pages, I want to display a list of the categories that reside below that category in the hierarchy. Also on the child category pages I want to display a list of the same child categories. I am thinking about it like this:

    if is category(x) or is child of category(x) then display children of category(x)

    Essentially, I always want to display the child categories, even when I'm on one of them.

    I really appreciate any advice.

  2. liberty50
    Member
    Posted 2 years ago #

    Here is what I have cobbled together so far:

    <?php
    if ( is_category() ) {
      $cat = get_query_var('cat');
      $args = array(
        'include' => $cat,
    	  'hide_empty' => 0
    	  );
      $categories = get_categories($args);
      if ( ($cat == 112) || ($categories[0]->category_parent == 112) ) {
    <?php wp_list_categories('child_of=112&title_li=') ?>
      }
    }
    ?>

    This works when I output echo 'test'; , but breaks when calling the category list. Any thoughts.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags