Changeset 565111
- Timestamp:
- 06/28/2012 08:51:18 PM (14 years ago)
- Location:
- 3pagination/trunk
- Files:
-
- 3 added
- 3 edited
-
3pagination.php (modified) (9 diffs)
-
class.settings.php (added)
-
examples/style.css (modified) (6 diffs)
-
js (added)
-
js/3pagination.js (added)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
3pagination/trunk/3pagination.php
r564699 r565111 1 1 <?php 2 2 3 /** 3 4 * Plugin Name: 3pagination 4 5 * Description: Reach any page with no more than 3 clicks 5 * Version: 1. 06 * Version: 1.2b 6 7 * Author: Michael Schröder <ms@ts-webdesign.net> 7 8 * TextDomain: 3pagination … … 9 10 */ 10 11 11 // Load example CSS 12 add_action( 'wp_enqueue_scripts', 'load_example_css' ); 13 14 // Example callback function 15 function load_example_css () { 16 wp_enqueue_style( 'threepagination-css', plugins_url( 'examples/style.css', __FILE__ ) ); 17 } 18 19 if ( ! class_exists( 'threepagination' ) ) { 12 if ( !class_exists( 'threepagination' ) ) { 20 13 21 14 class threepagination { 15 16 /** 17 * Textdomain string 18 * 19 * @var string 20 */ 21 protected $textdomain; 22 23 /** 24 * Class init 25 * 26 * @since 1.1 27 */ 28 public function __construct() { 29 30 // Get files 31 $this->include_files(); 32 33 // Set textdomain string 34 add_filter( 'admin_init', array( $this, 'set_textdomain' ), 1 ); 35 36 add_filter( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); 37 add_filter( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); 38 } 39 40 /** 41 * Include files 42 * 43 * @since 1.2b 44 */ 45 private function include_files() { 46 47 require_once( plugin_dir_path( __FILE__) . 'class.settings.php' ); 48 } 49 50 /** 51 * Set plugin's textdomain 52 * 53 * @since 1.2b 54 */ 55 public function set_textdomain() { 56 57 $this->textdomain = '3pagination'; 58 } 59 60 /** 61 * Load admin scripts 62 * 63 * @since 1.2b 64 */ 65 public function admin_scripts() { 66 67 wp_enqueue_style( 'threepagination-css', plugins_url( 'examples/style.css', __FILE__ ) ); 68 } 69 70 /** 71 * Load frontend scripts 72 * 73 * @since 1.2b 74 */ 75 public function frontend_scripts() { 76 77 wp_enqueue_style( 'threepagination-css', plugins_url( 'examples/style.css', __FILE__ ) ); 78 79 wp_enqueue_script( '3pagination-js', plugins_url( '/js/3pagination.js', __FILE__ ), array( 'jquery', 'json2' ) ); 80 wp_localize_script( '3pagination-js', 'threepag_vars', $this->frontend_vars() ); 81 } 82 83 /** 84 * Set frontend vars 85 * 86 * @return type 87 * @since 1.2b 88 */ 89 private function frontend_vars() { 90 91 $vars = array(); 92 93 $settings = get_option( '3pagination_settings' ); 94 95 // Check placement 96 if ( 'on' == $this->init_var( $settings, 'placement_header_index' ) && is_home() || 97 'on' == $this->init_var( $settings, 'placement_header_archive' ) && is_archive() || 98 'on' == $this->init_var( $settings, 'placement_header_category' ) && is_category() || 99 'on' == $this->init_var( $settings, 'placement_header_search' ) && is_search() ) 100 $vars[ 'placement_header' ] = TRUE; 101 102 if ( 'on' == $this->init_var( $settings, 'placement_footer_index' ) && is_home() || 103 'on' == $this->init_var( $settings, 'placement_footer_archive' ) && is_archive() || 104 'on' == $this->init_var( $settings, 'placement_footer_category' ) && is_category() || 105 'on' == $this->init_var( $settings, 'placement_footer_search' ) && is_search() ) 106 $vars[ 'placement_footer' ] = TRUE; 107 108 if ( 'on' == $this->init_var( $settings, 'placement_prepend_index' ) && is_home() || 109 'on' == $this->init_var( $settings, 'placement_prepend_archive' ) && is_archive() || 110 'on' == $this->init_var( $settings, 'placement_prepend_category' ) && is_category() || 111 'on' == $this->init_var( $settings, 'placement_prepend_search' ) && is_search() ) { 112 $vars[ 'placement_prepend' ] = TRUE; 113 $vars[ 'placement_prepend_id' ] = $settings[ 'placement_prepend_id' ]; 114 } 115 116 if ( 'on' == $this->init_var( $settings, 'placement_append_index' ) && is_home() || 117 'on' == $this->init_var( $settings, 'placement_append_archive' ) && is_archive() || 118 'on' == $this->init_var( $settings, 'placement_append_category' ) && is_category() || 119 'on' == $this->init_var( $settings, 'placement_append_search' ) && is_search() ) { 120 $vars[ 'placement_append' ] = TRUE; 121 $vars[ 'placement_append_id' ] = $settings[ 'placement_append_id' ]; 122 } 123 124 // HTML output 125 $vars[ 'html' ] = json_encode( self::get() ); 126 127 return $vars; 128 } 22 129 23 130 /** … … 33 140 * @since 0.1a 34 141 */ 35 public static function get ( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) {142 public static function get( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) { 36 143 37 144 global $wp_query, $wp; 38 145 39 146 // Get the page count 40 147 $total_pages = ( FALSE == $max_num_pages ) ? $wp_query->max_num_pages : $max_num_pages; … … 43 150 if ( 1 == $total_pages ) 44 151 return; 152 153 // For now, 3pagination supports up to 999 pages only 154 if ( 999 < $total_pages ) 155 $total_pages = 999; 45 156 46 157 // Get currently visited page … … 92 203 } 93 204 break; 94 205 95 206 default: 96 207 for ( $i = 1; $i <= 999; ++$i ) { … … 111 222 break; 112 223 } 224 225 $settings = get_option( '3pagination_settings' ); 226 227 $css = isset( $settings[ 'css_class' ] ) ? $settings[ 'css_class' ] : $css; 113 228 114 229 // Navigation labels 115 if ( FALSE !== $labels ) { 230 if ( FALSE !== $labels && 'on' == $settings[ 'labels_show' ] ) { 231 116 232 if ( $on_page > 1 ) { 117 233 $i = $on_page - 1; 118 $page_string = "<a class='page-numbers label-first' href='" . self::url( $wp, 1, $pretty ) . "'> «</a> " . $page_string;119 $page_string = "<a class='page-numbers label-previous' href='" . self::url( $wp, $i, $pretty ) . "'> ‹</a> " . $page_string;234 $page_string = "<a class='page-numbers label-first' href='" . self::url( $wp, 1, $pretty ) . "'>" . self::init_var( $settings, 'labels_first', '«', TRUE ) . "</a> " . $page_string; 235 $page_string = "<a class='page-numbers label-previous' href='" . self::url( $wp, $i, $pretty ) . "'>" . self::init_var( $settings, 'labels_previous', '‹', TRUE ) . "</a> " . $page_string; 120 236 } 121 237 122 238 if ( $on_page < $total_pages ) { 123 239 $i = $on_page + 1; 124 $page_string .= " <a class='page-numbers label-last' href='" . self::url( $wp, $total_pages, $pretty ) . "'> »</a>";125 $page_string .= " <a class='page-numbers label-next' href='" . self::url( $wp, $i, $pretty ) . "'> ›</a>";240 $page_string .= " <a class='page-numbers label-last' href='" . self::url( $wp, $total_pages, $pretty ) . "'>" . self::init_var( $settings, 'labels_last', '»', TRUE ) . "</a>"; 241 $page_string .= " <a class='page-numbers label-next' href='" . self::url( $wp, $i, $pretty ) . "'>" . self::init_var( $settings, 'labels_next', '›', TRUE ) . "</a>"; 126 242 } 127 243 } … … 133 249 return $page_string; 134 250 } 135 251 136 252 /** 137 253 * Main display function. Should be called in a static fashion: … … 148 264 * @since 0.1a 149 265 */ 150 public static function draw ( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) {266 public static function draw( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) { 151 267 152 268 echo self::get( $pretty, $max_num_pages, $labels, $css ); 153 269 } 154 270 155 271 /** 156 272 * Create link href … … 162 278 */ 163 279 private static function url( $wp, $i, $pretty ) { 164 280 281 // Pretty permalinks 165 282 if ( TRUE == $pretty ) { 166 283 if ( get_query_var( 'paged' ) ) 167 284 $url = preg_replace( '!(/page/\d+)/?$!', '/page/' . $i, home_url( $wp->request ) ); 168 else 169 $url = home_url( $wp->request ) . '/page/' . $i; 285 else 286 $url = home_url( $wp->request ) . '/page/' . $i; 170 287 } 288 // GET parameters 171 289 else 172 290 $url = home_url( $wp->request ) . '?paged=' . $i; 173 291 174 return $url; 175 } 176 292 //This might be a search query, where WP uses GET parameters (who knows why): 293 $params = parse_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ); 294 if ( isset( $params[ 'query' ] ) ) 295 $url.= '?' . $params[ 'query' ]; 296 297 return $url; 298 } 299 300 /** 301 * For not getting pissed of too much by PHP notices. This function should 302 * help to keep the "flow" of the code, i.e. limiting the amount of conditional 303 * statements in HTML blocks, etc. 304 * 305 * Example use: selected( $this->init_var( $var2, $index ), $var ) 306 * Instead of: if( !empty( $var2[ $index ] ) ) : selected( $var2[ $index ], $var ); endif; 307 * 308 * @access public 309 * @param var $var | the variable to check 310 * @param string $index | the index of the variable 311 * @param string, boolean $default | var default value 312 * @param bool $override_set_empty | Set var to default if it is emtpy 313 * @return var $var[ $index ] | the value of $var[ $index ] 314 * @since 0.1a 315 */ 316 public function init_var ( $var, $index, $default = FALSE, $override_set_empty = FALSE ) { 317 318 // is the $index of $var not yet set or (optional) set but empty? 319 if ( !isset( $var[ $index ] ) || ( TRUE == $override_set_empty && empty( $var[ $index ] ) ) ) 320 $var[ $index ] = ( FALSE == $default ) ? FALSE : $default; 321 322 return $var[ $index ]; 323 } 177 324 } 178 325 326 // Instantiate class 327 new threepagination(); 179 328 } 329 180 330 ?> -
3pagination/trunk/examples/style.css
r564699 r565111 8 8 /* Navigation items: classic style */ 9 9 .threepagination.classic { 10 margin: 30px 0px;11 width: 100%;10 clear: both; 11 margin: 30px 0px 20px; 12 12 padding: 5px; 13 13 overflow: hidden; … … 16 16 .threepagination.classic span.current { 17 17 display: inline-block; 18 padding: 0 3px;18 padding: 2px 2px 0; 19 19 margin: 2px -1px; 20 20 … … 36 36 /* Navigation items: classic-glow style */ 37 37 .threepagination.classic-glow { 38 margin: 30px 0px;39 width: 100%;38 clear: both; 39 margin: 30px 0px 20px; 40 40 padding: 5px; 41 41 overflow: hidden; … … 44 44 .threepagination.classic-glow span.current { 45 45 display: inline-block; 46 padding: 0 3px;46 padding: 2px 2px 0; 47 47 margin: 2px -1px; 48 48 … … 69 69 /* Navigation items: classic-small style */ 70 70 .threepagination.classic-small { 71 margin: 30px 0px; 72 width: 100%;71 clear: both; 72 margin: 30px 0px 20px; 73 73 padding: 5px; 74 74 overflow: hidden; … … 77 77 .threepagination.classic-small span.current { 78 78 display: inline-block; 79 padding: 0 3px;79 padding: 2px 2px 0; 80 80 margin: 1px -1px; 81 81 -
3pagination/trunk/readme.txt
r564703 r565111 3 3 Tags: pagination 4 4 Requires at least: 3.3.2 5 Tested up to: 3.4 6 Stable tag: 1. 05 Tested up to: 3.4.1 6 Stable tag: 1.2b 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 12 12 == Description == 13 13 14 Give your visitors the ability to easily access all your site's content. This is meant for sites with high page numbers. Any page between 1 and 999 can be accessed with a maximum of 3 clicks (see screenshots). 14 Give your visitors the ability to easily access all your site's content. Any page between 1 and 999 can be accessed with a maximum of 3 clicks (see screenshots). 15 <ul> 16 <li>Easy access to all your website's content.</li> 17 <li>Please searchengines by creating a more complete internal linking structure.</li> 18 <li>No need to modify theme files (see below)!</li> 19 <li>So far, this code has been tested on index, archive, category and search pages of some of the most popular WordPress themes.</li> 20 </ul> 15 21 16 So far, this code has been tested on index, archive and category pages of some of the most popular WordPress themes. 17 18 Please leave feedback, bug reports or comments at https://github.com/paddelboot/3pagination/issues 22 Please leave feedback, bug reports or comments at https://github.com/paddelboot/3pagination/issues. 19 23 20 24 == Installation == … … 25 29 3. Display the pagination using `<?php if ( class_exists( 'threepagination' ) ) : threepagination::draw(); endif; ?>` 26 30 31 <h4>Implementation</h4> 32 All options can be set in an options page, the pagination container can be injected or appended to the existing DOM. 33 27 34 <h4>Functions</h4> 35 You can, if you want (or to have your website degrade gracefully), call the class methods in your theme files. 36 28 37 draw() : Display the pagination 29 38 `draw ( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' )` … … 66 75 - Fixed support of custom css styles via function parameter 67 76 77 = 1.2b = 78 - Added backend settings page 79 - Inject pagination into DOM 80 - Support for search templates 81 68 82 == A brief Markdown Example == 69 83
Note: See TracChangeset
for help on using the changeset viewer.