WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am helping a friend make some changes to a wordpress theme. At the moment displaying subpages works only for one parent and its subpages (the one with id 31), but we want it to work for all pages (and their children). I want to more or less keep the code as is, just make the necessary changes to apply to all.

Although I am pretty good with css and html, php is not really my strong suit, so I would appreciate your help figuring this out. This is the existing code:

$currentPageId = get_the_ID();

$pages = get_pages('child_of=31');
foreach($pages as $child) {
$childrenPageID[$i] = $child->ID;

if ( (get_the_ID() == 31) || ( in_array($currentPageId, $childrenPageID)) ) {  

    $taxonomy     = 'portfoliocat';
    $orderby      = 'name'; 
    $show_count   = 0;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $child_of     = 5;
    $show_count   = 1;
    $title_li     = null;

    $args = array(
      'taxonomy'     => $taxonomy,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'child_of'     => $child_of,
      'show_count'   => $show_count,
      'title_li' => $title_li 


    <div style="overflow:auto; margin-bottom:20px;">
        <ul style="list-style-type:none; margin-left: 0px;">
        $cat = get_query_var('cat');

        // count all categories
        $totalCount = count(get_categories($args));
        $currentCount = 0;

        foreach(get_categories($args) as $category) {

            // get current number of stack
        $currentCount = $currentCount + 1;

        global $wpdb;
        $lookForValue = $category->slug;

        $querystr = "SELECT post_id
                     FROM $wpdb->postmeta
                     WHERE meta_key = 'category-include' AND meta_value = '".$lookForValue."';
        $postid = $wpdb->get_var($wpdb->prepare($querystr));

            // logic to remove last trunk
            if ($totalCount != $currentCount  ) {
            echo '<li class="cat-item"><a class="name" style="font-weight:bold" href="/?page_id='.$postid.'">' . $category->name.'</a>&nbsp;&nbsp;&nbsp;<span style="color: #999;">|</span>&nbsp;</li>';
            else {
            echo '<li class="cat-item"><a class="name" style="font-weight:bold" href="/?page_id='.$postid.'">' . $category->name.'</a></li>';   


I know I need to change the if, but no clue what to replace it with. Any suggestions?

Thanks in advance! Joanna

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.