Ticket #302: themes_pagination.patch

File themes_pagination.patch, 5.0 kB (added by momo360modena, 11 months ago)
  • themes.php

    old new  
    7979 
    8080<br style="clear: both" /> 
    8181<h2><?php _e('Available Themes'); ?></h2> 
    82 <?php if ( 1 < count($themes) ) { ?> 
    8382 
    8483<?php 
    85 $style = ''; 
     84if ( 1 < count($themes) ) {  
     85        $style = ''; 
    8686 
    87 $theme_names = array_keys($themes); 
    88 natcasesort($theme_names); 
     87        $theme_names = array_keys($themes); 
     88        natcasesort($theme_names); 
     89         
     90        // Remove current theme 
     91        foreach ( (array) $theme_names as $key => $theme_name) { 
     92                if ( $theme_name == $ct->name ) { 
     93                        unset($theme_names[$key]); 
     94                        break; 
     95                } 
     96        } 
    8997 
    90 foreach ($theme_names as $theme_name) { 
    91         if ( $theme_name == $ct->name ) 
    92                 continue; 
    93         $template = $themes[$theme_name]['Template']; 
    94         $stylesheet = $themes[$theme_name]['Stylesheet']; 
    95         $title = $themes[$theme_name]['Title']; 
    96         $version = $themes[$theme_name]['Version']; 
    97         $description = $themes[$theme_name]['Description']; 
    98         $author = $themes[$theme_name]['Author']; 
    99         $screenshot = $themes[$theme_name]['Screenshot']; 
    100         $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir']; 
    101         $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template); 
    102 ?> 
    103 <div class="available-theme"> 
    104 <h3><a href="<?php echo $activate_link; ?>"><?php echo $title; ?></a></h3> 
     98        // Pagination 
     99        $themes_per_page = (int) apply_filters('themes_per_page', 16); 
     100        $actual_page = (int) ( isset($_GET['pagination']) ) ? $_GET['pagination'] : 1; 
     101         
     102        $found_themes = count($theme_names); 
     103        $max_num_pages = ceil($found_themes/$themes_per_page); 
    105104 
    106 <a href="<?php echo $activate_link; ?>" class="screenshot"> 
    107 <?php if ( $screenshot ) : ?> 
    108 <img src="<?php echo get_option('siteurl') . '/' . $stylesheet_dir . '/' . $screenshot; ?>" alt="" /> 
    109 <?php endif; ?> 
    110 </a> 
     105        if( $actual_page != 1 ) { 
     106                if($actual_page > $max_num_pages) { 
     107                        $actual_page = $max_num_pages; 
     108                } 
     109        } 
    111110 
    112 <p><?php echo $description; ?></p> 
    113 </div> 
    114 <?php } // end foreach theme_names ?> 
     111        $start = ($actual_page - 1) * $themes_per_page; 
     112        $end = $start + $themes_per_page; 
     113         
     114        if ( $max_num_pages > 1 ) { 
     115                $output = '<div class="pagination">'; 
     116                $output .= __('Page: '); 
     117                for ( $i = 1; $i <= $max_num_pages; $i++ ) { 
     118                        $output .= '<a href="themes.php?pagination='.$i.'">'.$i.'</a>'; 
     119                } 
     120                $output = str_replace('pagination='.$actual_page.'">', 'pagination='.$actual_page.'" class="current_page">', $output); 
     121                $output .= '</div>'; 
     122                echo $output; 
     123        } 
     124                 
     125        $i = 0; 
     126        foreach ( (array) $theme_names as $theme_name) {                         
     127                if ( ($i >= $start) && ($i < $end) ) { 
     128                        $template = $themes[$theme_name]['Template']; 
     129                        $stylesheet = $themes[$theme_name]['Stylesheet']; 
     130                        $title = $themes[$theme_name]['Title']; 
     131                        $version = $themes[$theme_name]['Version']; 
     132                        $description = $themes[$theme_name]['Description']; 
     133                        $author = $themes[$theme_name]['Author']; 
     134                        $screenshot = $themes[$theme_name]['Screenshot']; 
     135                        $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir']; 
     136                        $activate_link = wp_nonce_url("themes.php?action=activate&amp;pagination=".$actual_page."&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template); 
     137                        ?> 
     138                        <div class="available-theme"> 
     139                                <h3><a href="<?php echo $activate_link; ?>"><?php echo $title; ?></a></h3> 
    115140 
    116 <?php } ?> 
     141                                <a href="<?php echo $activate_link; ?>" class="screenshot"> 
     142                                        <?php if ( $screenshot ) : ?> 
     143                                                <img src="<?php echo get_option('siteurl') . '/' . $stylesheet_dir . '/' . $screenshot; ?>" alt="<?php echo attribute_escape(strip_tags($title)); ?>" /> 
     144                                        <?php endif; ?> 
     145                                </a> 
     146                                <p><?php echo $description; ?></p> 
     147                        </div> 
     148                        <?php 
     149                } 
     150                $i++; 
     151        } // end foreach theme_names  
     152         
     153        if ( $max_num_pages > 1 ) { 
     154                $output = '<div class="pagination">'; 
     155                $output .= __('Page: '); 
     156                for ( $i = 1; $i <= $max_num_pages; $i++ ) { 
     157                        $output .= '<a href="themes.php?pagination='.$i.'">'.$i.'</a>'; 
     158                } 
     159                $output = str_replace('pagination='.$actual_page.'">', 'pagination='.$actual_page.'" class="current_page">', $output); 
     160                $output .= '</div>'; 
     161                echo $output; 
     162        } 
     163        ?> 
     164        <style type="text/css"> 
     165                .pagination { clear:both;text-align:center; } 
     166                .pagination a { margin: 0 3px; } 
     167                .pagination a.current_page { font-weight:700; } 
     168        </style>         
     169        <?php 
     170
    117171 
    118 <?php 
    119172// List broken themes, if any. 
    120173$broken_themes = get_broken_themes(); 
    121174if ( is_site_admin() && count($broken_themes) ) { 
    122175?> 
    123176 
    124 <h2><?php _e('Broken Themes'); ?> (Site admin only)</h2> 
     177<h2><?php _e('Broken Themes (Site admin only)'); ?></h2> 
    125178<p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p> 
    126179 
    127180<table width="100%" cellpadding="3" cellspacing="3"> 
     
    141194 
    142195                $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"'; 
    143196                echo " 
    144                 <tr $theme> 
    145                          <td>$title</td> 
    146                          <td>$description</td> 
    147                 </tr>"; 
     197                       <tr $theme> 
     198                               <td>$title</td> 
     199                               <td>$description</td> 
     200                       </tr>"; 
    148201        } 
    149202?> 
    150203</table>