* TextDomain: 3pagination * DomainPath: /l10n */ // Load example CSS add_action( 'wp_enqueue_scripts', 'load_example_css' ); // Example callback function function load_example_css () { wp_enqueue_style( 'threepagination-css', plugins_url( 'examples/style.css', __FILE__ ) ); } if ( ! class_exists( 'threepagination' ) ) { class threepagination { /** * Returns a HTML string containing the navigation. * * @global object $wp_query | the current query object used to gather pagination information * @global type $wp * @param bool $pretty | pretty permalink strukture. TRUE or FALSE * @param int $num_items | can be used to override the global number of items * @param int $per_page | can be used to override the global posts per page * @param bool $labels | show labels, TRUE or FALSE * @param string $css | the css class name appended to the 'threepagination' wrapper div * @return void * @since 0.1a */ public static function get ( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) { global $wp_query, $wp; // Get the page count $total_pages = ( FALSE == $max_num_pages ) ? $wp_query->max_num_pages : $max_num_pages; // No need for navi if ( 1 == $total_pages ) return; // Get currently visited page $on_page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $digits = strlen( $on_page ); $page_string = ''; // Start some complicated calculations. The benfit should // be a navigation that lets you navigate to any page between 1 and 999 // without more than 3 mouse clicks. Maximum page number is 999. switch ( $digits ) { case 1: case 2: for ( $i = 1; $i <= $total_pages; ++$i ) { if ( $i == 1 OR ($i <= 10 AND $digits == 1) OR ($i < 100 AND substr( $i, -2, 1 ) == substr( $on_page, -2, 1 ) AND $digits == strlen( $i )) OR ($i >= 10 AND $i < 100 AND is_int( $i / 10 )) OR (is_int( $i / 100 )) OR ($i == $total_pages) ) { $url = self::url( $wp, $i, $pretty ); $page_string .= ( $i == $on_page ) ? "" . $i . "" : "" . $i . ""; if ( $i < $total_pages ) { $page_string .= " "; } } } break; case 3: for ( $i = 1; $i <= $total_pages; ++$i ) { if ( $i == 1 OR ($i >= 100 AND substr( $i, -3, 2 ) == substr( $on_page, -3, 2 )) OR ($i >= 100 AND is_int( $i / 10 ) AND substr( $i, -3, 1 ) == substr( $on_page, -3, 1 )) OR (is_int( $i / 100 )) OR ($i == $total_pages) ) { $url = self::url( $wp, $i, $pretty ); $page_string .= ( $i == $on_page ) ? "" . $i . "" : "" . $i . ""; if ( $i < $total_pages ) { $page_string .= " "; } } } break; default: for ( $i = 1; $i <= 999; ++$i ) { if ( $i == 1 OR ($i >= 100 AND substr( $i, -3, 2 ) == substr( $on_page, -3, 2 )) OR ($i >= 100 AND is_int( $i / 10 ) AND substr( $i, -3, 1 ) == substr( $on_page, -3, 1 )) OR (is_int( $i / 100 )) OR ($i == $total_pages) ) { $url = self::url( $wp, $i, $pretty ); $page_string .= ( $i == $on_page ) ? "" . $i . "" : "" . $i . ""; if ( $i < $total_pages ) { $page_string .= " "; } } } break; } // Navigation labels if ( FALSE !== $labels ) { if ( $on_page > 1 ) { $i = $on_page - 1; $page_string = "« " . $page_string; $page_string = "‹ " . $page_string; } if ( $on_page < $total_pages ) { $i = $on_page + 1; $page_string .= " ›"; $page_string .= " »"; } } // Glue together the HTML string $page_string = "