Ticket #1189: dropdown_pages.diff

File dropdown_pages.diff, 3.5 KB (added by anonymousbugger, 7 years ago)
  • template-functions-post.php

     
    311311        if (!isset($r['depth'])) $r['depth'] = 0; 
    312312        if (!isset($r['show_date'])) $r['show_date'] = ''; 
    313313        if (!isset($r['child_of'])) $r['child_of'] = 0; 
    314         if ( !isset($r['title_li']) ) $r['title_li'] = __('Pages'); 
     314        if (!isset($r['title_li']) ) $r['title_li'] = __('Pages'); 
     315        if (!isset($r['style'])) $r['style'] = 'list'; 
    315316 
    316  
    317317        // Query pages. 
    318318        $pages = & get_pages($args); 
    319319        if ( $pages ) : 
    320320 
    321         if ( $r['title_li'] ) 
     321        if ( $r['title_li'] && 'list' == $r['style'] ) 
    322322                echo '<li id="pagenav">' . $r['title_li'] . '<ul>'; 
     323        else 
     324                echo "<select name='page_id'>\n"; 
     325 
    323326        // Now loop over all pages that were selected 
    324327        $page_tree = Array(); 
    325328        foreach($pages as $page) { 
     
    350353        // Output of the pages starting with child_of as the root ID. 
    351354        // child_of defaults to 0 if not supplied in the query. 
    352355        _page_level_out($r['child_of'],$page_tree, $r); 
    353         if ( $r['title_li'] ) 
     356        if ( $r['title_li'] && 'list' == $r['style'] ) 
    354357                echo '</ul></li>'; 
     358        else 
     359                echo "</select>\n"; 
    355360        endif; 
    356361} 
    357362 
     
    360365 
    361366        $queried_obj = $wp_query->get_queried_object(); 
    362367 
    363         if($depth) 
     368        if ($depth) { 
    364369                $indent = str_repeat("\t", $depth); 
    365         //$indent = join('', array_fill(0,$depth,"\t")); 
     370                $pad = str_repeat('&nbsp;', $depth * 3); 
     371        } 
    366372 
    367373        foreach($page_tree[$parent]['children'] as $page_id) { 
    368374                $cur_page = $page_tree[$page_id]; 
    369375                $title = $cur_page['title']; 
    370376 
    371                 $css_class = 'page_item'; 
    372                 if( $page_id == $queried_obj->ID) { 
    373                         $css_class .= ' current_page_item'; 
    374                 } 
    375  
    376                 echo $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>'; 
    377  
    378                 if(isset($cur_page['ts'])) { 
    379                         $format = get_settings('date_format'); 
     377                if ('list' == $args['style']) { 
     378                        $css_class = 'page_item'; 
     379                        if( $page_id == $queried_obj->ID) { 
     380                                $css_class .= ' current_page_item'; 
     381                        } 
     382                         
     383                        echo $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>'; 
     384                         
     385                        if(isset($cur_page['ts'])) { 
     386                                $format = get_settings('date_format'); 
    380387                        if(isset($args['date_format'])) 
    381388                                $format = $args['date_format']; 
    382389                        echo " " . mysql2date($format,$cur_page['ts']); 
    383                 } 
    384                 echo "\n"; 
    385  
    386                 if(isset($cur_page['children']) && is_array($cur_page['children'])) { 
    387                         $new_depth = $depth + 1; 
    388  
    389                         if(!$args['depth'] || $depth < ($args['depth']-1)) { 
    390                                 echo "$indent<ul>\n"; 
    391                                 _page_level_out($page_id,$page_tree, $args, $new_depth); 
    392                                 echo "$indent</ul>\n"; 
    393390                        } 
     391                        echo "\n"; 
     392                         
     393                        if(isset($cur_page['children']) && is_array($cur_page['children'])) { 
     394                                $new_depth = $depth + 1; 
     395                                 
     396                                if(!$args['depth'] || $depth < ($args['depth']-1)) { 
     397                                        echo "$indent<ul>\n"; 
     398                                        _page_level_out($page_id, $page_tree, $args, $new_depth); 
     399                                        echo "$indent</ul>\n"; 
     400                                } 
     401                        } 
     402                        echo "$indent</li>\n"; 
     403                } elseif ('dropdown' == $args['style']) { 
     404                        echo "\t<option value=\"".$page_id."\""; 
     405                        if ($page_id == $queried_obj->ID) 
     406                                echo ' selected="selected"'; 
     407                        echo '>'; 
     408                        echo "$pad$title"; 
     409                        echo "</option>\n"; 
     410                        if(isset($cur_page['children']) && is_array($cur_page['children'])) { 
     411                                $new_depth = $depth + 1; 
     412                                _page_level_out($page_id, $page_tree, $args, $new_depth); 
     413                        } 
    394414                } 
    395                 echo "$indent</li>\n"; 
    396415        } 
    397416} 
    398417