Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
$i=0;
foreach($pages as $child) {
$childrenPageID[$i] = $child->ID;
$i++;
}

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;">
        <?php
        $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>';   
            }
        }?>
        </ul>
   </div>

 }

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
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.