source: trunk/www.guidonia.net/wp/wp-content/plugins/wp-page-numbers/wp-page-numbers.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 17.6 KB
Line 
1<?php
2/*
3Plugin Name: WP Page Numbers
4Plugin URI: http://www.jenst.se/2008/03/29/wp-page-numbers
5Description: Show pages numbers instead of "Next page" and "Previous Page".
6Version: 0.5
7Author: Jens T&ouml;rnell
8Author URI: http://www.jenst.se
9*/
10
11function wp_page_numbers_stylesheet()
12{
13 $settings = get_option('wp_page_numbers_array');
14 $head_stylesheet = $settings["head_stylesheetsheet"];
15 $head_stylesheet_folder_name = $settings["head_stylesheetsheet_folder_name"];
16 $style_theme = $settings["style_theme"];
17
18 if($head_stylesheet == "on" || $head_stylesheet == "" && (is_archive() || is_search() || is_home() ||is_page()))
19 {
20 echo '<link rel="stylesheet" href="'. get_bloginfo('wpurl') . '/wp-content/plugins/wp-page-numbers/';
21 if($head_stylesheet_folder_name == "")
22 {
23 if($style_theme == "default")
24 echo 'default';
25 elseif($style_theme == "classic")
26 echo 'classic';
27 elseif($style_theme == "tiny")
28 echo 'tiny';
29 elseif($style_theme == "panther")
30 echo 'panther';
31 elseif($style_theme == "stylish")
32 echo 'stylish';
33 else
34 echo 'default';
35 }
36 else
37 echo $head_stylesheet_folder_name;
38 echo '/wp-page-numbers.css" type="text/css" media="screen" />';
39 }
40}
41add_action('wp_head', 'wp_page_numbers_stylesheet');
42
43function wp_page_numbers_check_num($num)
44{
45 return ($num%2) ? true : false;
46}
47
48function wp_page_numbers_page_of_page($max_page, $paged, $page_of_page_text, $page_of_of)
49{
50 $pagingString = "";
51 if ( $max_page > 1)
52 {
53 $pagingString .= '<li class="page_info">';
54 if($page_of_page_text == "")
55 $pagingString .= 'Page ';
56 else
57 $pagingString .= $page_of_page_text . ' ';
58
59 if ( $paged != "" )
60 $pagingString .= $paged;
61 else
62 $pagingString .= 1;
63
64 if($page_of_of == "")
65 $pagingString .= ' of ';
66 else
67 $pagingString .= ' ' . $page_of_of . ' ';
68 $pagingString .= floor($max_page).'</li>';
69 }
70 return $pagingString;
71}
72
73function wp_page_numbers_prevpage($paged, $max_page, $prevpage)
74{
75 if( $max_page > 1 && $paged > 1 )
76 $pagingString = '<li><a href="'.get_pagenum_link($paged-1). '">'.$prevpage.'</a></li>';
77 return $pagingString;
78}
79
80function wp_page_numbers_left_side($max_page, $limit_pages, $paged, $pagingString)
81{
82 $pagingString = "";
83 $page_check_max = false;
84 $page_check_min = false;
85 if($max_page > 1)
86 {
87 for($i=1; $i<($max_page+1); $i++)
88 {
89 if( $i <= $limit_pages )
90 {
91 if ($paged == $i || ($paged == "" && $i == 1))
92 $pagingString .= '<li class="active_page"><a href="'.get_pagenum_link($i). '">'.$i.'</a></li>'."\n";
93 else
94 $pagingString .= '<li><a href="'.get_pagenum_link($i). '">'.$i.'</a></li>'."\n";
95 if ($i == 1)
96 $page_check_min = true;
97 if ($max_page == $i)
98 $page_check_max = true;
99 }
100 }
101 return array($pagingString, $page_check_max, $page_check_min);
102 }
103}
104
105function wp_page_numbers_middle_side($max_page, $paged, $limit_pages_left, $limit_pages_right)
106{
107 $pagingString = "";
108 $page_check_max = false;
109 $page_check_min = false;
110 for($i=1; $i<($max_page+1); $i++)
111 {
112 if($paged-$i <= $limit_pages_left && $paged+$limit_pages_right >= $i)
113 {
114 if ($paged == $i)
115 $pagingString .= '<li class="active_page"><a href="'.get_pagenum_link($i). '">'.$i.'</a></li>'."\n";
116 else
117 $pagingString .= '<li><a href="'.get_pagenum_link($i). '">'.$i.'</a></li>'."\n";
118
119 if ($i == 1)
120 $page_check_min = true;
121 if ($max_page == $i)
122 $page_check_max = true;
123 }
124 }
125 return array($pagingString, $page_check_max, $page_check_min);
126}
127
128function wp_page_numbers_right_side($max_page, $limit_pages, $paged, $pagingString)
129{
130 $pagingString = "";
131 $page_check_max = false;
132 $page_check_min = false;
133 for($i=1; $i<($max_page+1); $i++)
134 {
135 if( ($max_page + 1 - $i) <= $limit_pages )
136 {
137 if ($paged == $i)
138 $pagingString .= '<li class="active_page"><a href="'.get_pagenum_link($i). '">'.$i.'</a></li>'."\n";
139 else
140 $pagingString .= '<li><a href="'.get_pagenum_link($i). '">'.$i.'</a></li>'."\n";
141
142 if ($i == 1)
143 $page_check_min = true;
144 }
145 if ($max_page == $i)
146 $page_check_max = true;
147
148 }
149 return array($pagingString, $page_check_max, $page_check_min);
150}
151
152function wp_page_numbers_nextpage($paged, $max_page, $nextpage)
153{
154 if( $paged != "" && $paged < $max_page)
155 $pagingString = '<li><a href="'.get_pagenum_link($paged+1). '">'.$nextpage.'</a></li>'."\n";
156 return $pagingString;
157}
158
159function wp_page_numbers($start = "", $end = "")
160{
161 global $wp_query;
162 global $max_page;
163 global $paged;
164 if ( !$max_page ) { $max_page = $wp_query->max_num_pages; }
165 if ( !$paged ) { $paged = 1; }
166
167 $settings = get_option('wp_page_numbers_array');
168 $page_of_page = $settings["page_of_page"];
169 $page_of_page_text = $settings["page_of_page_text"];
170 $page_of_of = $settings["page_of_of"];
171
172 $next_prev_text = $settings["next_prev_text"];
173 $show_start_end_numbers = $settings["show_start_end_numbers"];
174 $show_page_numbers = $settings["show_page_numbers"];
175
176 $limit_pages = $settings["limit_pages"];
177 $nextpage = $settings["nextpage"];
178 $prevpage = $settings["prevpage"];
179 $startspace = $settings["startspace"];
180 $endspace = $settings["endspace"];
181
182 if( $nextpage == "" ) { $nextpage = "&gt;"; }
183 if( $prevpage == "" ) { $prevpage = "&lt;"; }
184 if( $startspace == "" ) { $startspace = "..."; }
185 if( $endspace == "" ) { $endspace = "..."; }
186
187 if($limit_pages == "") { $limit_pages = "10"; }
188 elseif ( $limit_pages == "0" ) { $limit_pages = $max_page; }
189
190 if(wp_page_numbers_check_num($limit_pages) == true)
191 {
192 $limit_pages_left = ($limit_pages-1)/2;
193 $limit_pages_right = ($limit_pages-1)/2;
194 }
195 else
196 {
197 $limit_pages_left = $limit_pages/2;
198 $limit_pages_right = ($limit_pages/2)-1;
199 }
200
201 if( $max_page <= $limit_pages ) { $limit_pages = $max_page; }
202
203 $pagingString = "<div id='wp_page_numbers'>\n";
204 $pagingString .= '<ul>';
205
206 if($page_of_page != "no")
207 $pagingString .= wp_page_numbers_page_of_page($max_page, $paged, $page_of_page_text, $page_of_of);
208
209 if( ($paged) <= $limit_pages_left )
210 {
211 list ($value1, $value2, $page_check_min) = wp_page_numbers_left_side($max_page, $limit_pages, $paged, $pagingString);
212 $pagingMiddleString .= $value1;
213 }
214 elseif( ($max_page+1 - $paged) <= $limit_pages_right )
215 {
216 list ($value1, $value2, $page_check_min) = wp_page_numbers_right_side($max_page, $limit_pages, $paged, $pagingString);
217 $pagingMiddleString .= $value1;
218 }
219 else
220 {
221 list ($value1, $value2, $page_check_min) = wp_page_numbers_middle_side($max_page, $paged, $limit_pages_left, $limit_pages_right);
222 $pagingMiddleString .= $value1;
223 }
224 if($next_prev_text != "no")
225 $pagingString .= wp_page_numbers_prevpage($paged, $max_page, $prevpage);
226
227 if ($page_check_min == false && $show_start_end_numbers != "no")
228 {
229 $pagingString .= "<li class=\"first_last_page\">";
230 $pagingString .= "<a href=\"" . get_pagenum_link(1) . "\">1</a>";
231 $pagingString .= "</li>\n<li class=\"space\">".$startspace."</li>\n";
232 }
233
234 if($show_page_numbers != "no")
235 $pagingString .= $pagingMiddleString;
236
237 if ($value2 == false && $show_start_end_numbers != "no")
238 {
239 $pagingString .= "<li class=\"space\">".$endspace."</li>\n";
240 $pagingString .= "<li class=\"first_last_page\">";
241 $pagingString .= "<a href=\"" . get_pagenum_link($max_page) . "\">" . $max_page . "</a>";
242 $pagingString .= "</li>\n";
243 }
244
245 if($next_prev_text != "no")
246 $pagingString .= wp_page_numbers_nextpage($paged, $max_page, $nextpage);
247
248 $pagingString .= "</ul>\n";
249
250 $pagingString .= "<div style='float: none; clear: both;'></div>\n";
251 $pagingString .= "</div>\n";
252
253 if($max_page > 1)
254 echo $start . $pagingString . $end;
255}
256
257function wp_page_numbers_settings()
258{
259 if(isset($_POST['submitted']))
260 {
261 if($_POST["head_stylesheetsheet"] == "")
262 $_POST["head_stylesheetsheet"] = "no";
263 if($_POST["page_of_page"] == "")
264 $_POST["page_of_page"] = "no";
265 if($_POST["next_prev_text"] == "")
266 $_POST["next_prev_text"] = "no";
267 if($_POST["show_start_end_numbers"] == "")
268 $_POST["show_start_end_numbers"] = "no";
269 if($_POST["show_page_numbers"] == "")
270 $_POST["show_page_numbers"] = "no";
271 if($_POST["style_theme"] == "")
272 $_POST["style_theme"] = "default";
273
274 $settings = array (
275 "head_stylesheetsheet" => $_POST["head_stylesheetsheet"],
276 "head_stylesheetsheet_folder_name" => $_POST["head_stylesheetsheet_folder_name"],
277 "page_of_page" => $_POST["page_of_page"],
278 "page_of_page_text" => $_POST["page_of_page_text"],
279 "page_of_of" => $_POST["page_of_of"],
280 "next_prev_text" => $_POST["next_prev_text"],
281 "show_start_end_numbers" => $_POST["show_start_end_numbers"],
282 "show_page_numbers" => $_POST["show_page_numbers"],
283 "limit_pages" => $_POST["limit_pages"],
284 "nextpage" => $_POST["nextpage"],
285 "prevpage" => $_POST["prevpage"],
286 "startspace" => $_POST["startspace"],
287 "endspace" => $_POST["endspace"],
288 "style_theme" => $_POST["style_theme"],
289 );
290 update_option('wp_page_numbers_array', $settings);
291
292 echo "<div id=\"message\" class=\"updated fade\"><p><strong>WP Page Numbers plugin options updated.</strong></p></div>";
293 }
294
295 $settings = get_option('wp_page_numbers_array');
296
297 $style_theme = $settings["style_theme"];
298
299 $head_stylesheet = $settings["head_stylesheetsheet"];
300 $head_stylesheet_folder_name = $settings["head_stylesheetsheet_folder_name"];
301 $page_of_page = $settings["page_of_page"];
302 $page_of_page_text = $settings["page_of_page_text"];
303 $page_of_of = $settings["page_of_of"];
304
305 $next_prev_text = $settings["next_prev_text"];
306 $show_start_end_numbers = $settings["show_start_end_numbers"];
307 $show_page_numbers = $settings["show_page_numbers"];
308
309 $limit_pages = $settings["limit_pages"];
310
311 $nextpage = $settings["nextpage"];
312 $prevpage = $settings["prevpage"];
313 $startspace = $settings["startspace"];
314 $endspace = $settings["endspace"];
315
316 ?>
317<form method="post" name="options" target="_self">
318
319<div class="wrap">
320<h2>Page Number Themes</h2>
321<table style="width: 100%;" border="0">
322 <tr>
323 <td><strong>Use themes?</strong></td>
324 <td>
325 <input type="checkbox" name="head_stylesheetsheet" <?php
326 if($head_stylesheet == "on" || $head_stylesheet == "")
327 {
328 echo 'checked="checked"';
329 }
330 ?>/> Include theme stylesheet for page numbers
331 </td>
332 </tr>
333 <tr>
334 <td style="width: 400px;"><strong>Modern</strong></td>
335 <td style="padding-top: 5px; padding-bottom: 5px;">
336 <input type="radio" name="style_theme" value="default" <?php
337 if( ( $style_theme == "default" || $style_theme == "" ) && $head_stylesheet_folder_name == "" )
338 {
339 echo 'checked="checked"';
340 }
341 ?>/>
342 <img src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-page-numbers/default/preview.gif" alt="" />
343 </td>
344 </tr>
345 <tr>
346 <td><strong>Classic</strong></td>
347 <td style="padding-top: 5px; padding-bottom: 5px;">
348 <input type="radio" name="style_theme" value="classic" <?php
349 if($style_theme == "classic" && $head_stylesheet_folder_name == "")
350 {
351 echo 'checked="checked"';
352 }
353 ?>/>
354 <img src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-page-numbers/classic/preview.gif" alt="" />
355 </td>
356 </tr>
357 <tr>
358 <td><strong>Tiny</strong></td>
359 <td style="padding-top: 5px; padding-bottom: 5px;">
360 <input type="radio" name="style_theme" value="tiny" <?php
361 if($style_theme == "tiny" && $head_stylesheet_folder_name == "")
362 {
363 echo 'checked="checked"';
364 }
365 ?>/>
366 <img src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-page-numbers/tiny/preview.gif" alt="" />
367 </td>
368 </tr>
369 <tr>
370 <td><strong>Panther</strong></td>
371 <td style="padding-top: 5px; padding-bottom: 5px;">
372 <input type="radio" name="style_theme" value="panther" <?php
373 if($style_theme == "panther" && $head_stylesheet_folder_name == "")
374 {
375 echo 'checked="checked"';
376 }
377 ?>/>
378 <img src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-page-numbers/panther/preview.gif" alt="" />
379 </td>
380 </tr>
381 <tr>
382 <td><strong>Stylish</strong></td>
383 <td style="padding-top: 5px; padding-bottom: 5px;">
384 <input type="radio" name="style_theme" value="stylish" <?php
385 if($style_theme == "stylish" && $head_stylesheet_folder_name == "")
386 {
387 echo 'checked="checked"';
388 }
389 ?>/>
390 <img src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-page-numbers/stylish/preview.gif" alt="" />
391 </td>
392 </tr>
393 <tr>
394 <td><strong>Theme folder name: </strong><span style="color: red;">OVERRIDE</span> settings above</td>
395 <td colspan="3">
396 <input name="head_stylesheetsheet_folder_name" type="text" style="width:100%;" value="<?php echo $head_stylesheet_folder_name; ?>" />
397 </td>
398 </tr>
399
400 <tr>
401 <td></td>
402 <td colspan="2">
403 - Have you create a cool WP Page Numbers theme?<br />
404 - Want to share it to the rest of the world? <a href="http://www.jenst.se/2008/03/29/wp-page-numbers/">Write a comment about it</a>.
405 </td>
406 </tr>
407</table>
408</div>
409
410<div class="wrap">
411<h2>Settings - Text</h2>
412<table style="width: 100%;" border="0">
413
414 <tr>
415 <td style="width: 400px;"><strong>Default text: </strong>Page</td>
416 <td colspan="3">
417 <input name="page_of_page_text" type="text" style="width:100%;" value="<?php echo $page_of_page_text; ?>" />
418 </td>
419 </tr>
420
421 <tr>
422 <td><strong>Default text: </strong>of</td>
423 <td colspan="3">
424 <input name="page_of_of" type="text" style="width:100%;" value="<?php echo $page_of_of; ?>" />
425 </td>
426 </tr>
427
428 <tr>
429 <td><strong>Default text: </strong>&lt;</td>
430 <td colspan="3">
431 <input name="prevpage" type="text" style="width:100%;" value="<?php echo $prevpage; ?>" />
432 </td>
433 </tr>
434
435 <tr>
436 <td><strong>Default text: </strong>...</td>
437 <td colspan="3">
438 <input name="startspace" type="text" style="width:100%;" value="<?php echo $startspace; ?>" />
439 </td>
440 </tr>
441
442 <tr>
443 <td><strong>Default text: </strong>...</td>
444 <td colspan="3">
445 <input name="endspace" type="text" style="width:100%;" value="<?php echo $endspace; ?>" />
446 </td>
447 </tr>
448
449 <tr>
450 <td><strong>Default text: </strong>&gt;</td>
451 <td colspan="3">
452 <input name="nextpage" type="text" style="width:100%;" value="<?php echo $nextpage; ?>" />
453 </td>
454 </tr>
455</table>
456</div>
457
458<div class="wrap">
459<h2>Settings - show / hide</h2>
460<table style="width: 100%;" border="0">
461
462 <tr>
463 <td style="width: 400px;"><strong>Show page info</strong></td>
464 <td>
465 <input type="checkbox" name="page_of_page" <?php
466 if($page_of_page == "on" || $page_of_page == "")
467 {
468 echo 'checked="checked"';
469 }
470 ?>/> Page 3 of 5
471 </td>
472 </tr>
473
474 <tr>
475 <td><strong>Show next / previous page text</td>
476 <td>
477 <input type="checkbox" name="next_prev_text" <?php
478 if($next_prev_text == "on" || $next_prev_text == "")
479 {
480 echo 'checked="checked"';
481 }
482 ?>/> &lt; &gt;
483 </td>
484 </tr>
485
486 <tr>
487 <td><strong>Show start and end numbers</td>
488 <td>
489 <input type="checkbox" name="show_start_end_numbers" <?php
490 if($show_start_end_numbers == "on" || $show_start_end_numbers == "")
491 {
492 echo 'checked="checked"';
493 }
494 ?>/> 1... ...5
495 </td>
496 </tr>
497
498 <tr>
499 <td><strong>Show page numbers</td>
500 <td>
501 <input type="checkbox" name="show_page_numbers" <?php
502 if($show_page_numbers == "on" || $show_page_numbers == "")
503 {
504 echo 'checked="checked"';
505 }
506 ?>/> 34567
507 </td>
508 </tr>
509</table>
510</div>
511
512<div class="wrap">
513<h2>Settings - Misc</h2>
514<table style="width: 100%;" border="0">
515 <tr>
516 <td style="width: 400px;"><strong>Number of pages to show: </strong>10 (0 = unlimited)</td>
517 <td colspan="3">
518 <input name="limit_pages" type="text" style="width:100%;" value="<?php echo $limit_pages; ?>" />
519 </td>
520 </tr>
521</table>
522</div>
523
524<div class="wrap">
525<h2>Instructions - Code to add to your theme</h2>
526 <p>Add the code where you find <code>previous_post()</code> and <code>next_post()</code> functions. If you can't find these tags, place the code between <code>endwhile;</code> and <code>endif;</code> in the_loop.</p>
527 <table>
528 <tr>
529 <td><strong>Code to add in your theme</strong></td>
530 </tr>
531 <tr>
532 <td colspan="2"><code>&lt;?php if(function_exists('wp_page_numbers')) : wp_page_numbers(); endif; ?&gt;</code><br /><br /></td>
533 </tr>
534 <tr>
535 <td><strong>Advanced (optional) settings</strong><br /><br /></td>
536 </tr>
537 <tr>
538 <td style="width: 400px;"><strong>Syntax:</strong> <code>wp_page_numbers($start, $end);</code></td>
539 <td><strong>Example:</strong> <code>wp_page_numbers("&lt;div class='start'&gt;", "&lt;/div&gt;");</code></td>
540 </tr>
541 </table>
542</div>
543
544<div class="wrap">
545<h2>Instructions - Settings</h2>
546 <p>Most of the settings are already set to a default value if blank.</p>
547 <table>
548 <tr>
549 <td><strong>Text options</strong></td>
550 </tr>
551 <tr>
552 <td>You can set all the texts to what ever you like, except the numbers. They will still be numbers.<br /><br /></td>
553 </tr>
554
555 <tr>
556 <td><strong>Number of pages to show</strong></td>
557 </tr>
558 <tr>
559 <td>This will limit your paging menu. Set a of maximum amount of pages to be displayed at the same time. If the textfield is blank, 10 is set by default. If 0 is set, it will not limit the paging.<br /><br /></td>
560 </tr>
561 <tr>
562 <td><strong>Theme folder name</strong></td>
563 </tr>
564 <tr>
565 <td>
566 <ol>
567 <li>Copy one of the theme folders</li>
568 <li>Edit the '<strong>wp-page-numbers.css</strong>' to make your changes</li>
569 <li>Rename your folder copy to a theme name</li>
570 <li>Upload your folder into '<strong>wp-content/plugins/wp-page-numbers/</strong>'</li>
571 <li>Set your '<strong>Theme folder name</strong>' in admin '<strong>Settings / WP Page Numbers</strong>'</li>
572 <li>'<strong>Update settings</strong>'. Done!</li>
573 </ol>
574 </td>
575 </tr>
576 </table>
577
578 <p class="submit">
579 <input name="submitted" type="hidden" value="yes" />
580 <input type="submit" name="Submit" value="Update Settings &raquo;" />
581 </p>
582</form>
583</div><?php
584}
585
586function wp_page_numbers_add_to_menu() {
587 add_submenu_page('options-general.php', 'WP Page Numbers Options', 'Page Numbers', 10, __FILE__, 'wp_page_numbers_settings');
588}
589add_action('admin_menu', 'wp_page_numbers_add_to_menu');
590?>
Note: See TracBrowser for help on using the repository browser.