Paggination

<?php // functions.php function generate_pagination($loop){ $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged')), // current page 'total' => $loop->max_num_pages, 'prev_text' => '<<', 'next_text' => '>>', 'type' => 'list' )); } ?> <!-- 2 sposoby na zadeklarowania $loop --> <!-- (1) --> <?php $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $args = array( 'post_type' => 'post', 'paged' => $paged // !!! ); $loop = new WP_Query( $args ); ?> <!-- (2) --> <?php $query_params = getQueryParams(); //wartosci z query_string, m.in ustawione juz 'post_type' i 'paged' (2a) $loop = new WP_Query($query_params); ?> <!-- (2a) --> <?php function getQueryParams(){ // wyciaganie wartosci z query_string global $query_string; $parts = explode('&', $query_string); $return = array(); foreach($parts as $part){ $tmp = explode('=', $part); $return[$tmp[0]] = trim(urldecode($tmp[1])); } return $return; } ?> <!-- Uzycie Paginacji --> <?php generate_pagination($loop); ?> ---------------------------------------------------------------------------------------------- Funkcja generuje nastepujaca strukture: <ul> <li><a></a></li> dla linku aktywnego <li><span></span></li> dla linku nie aktywnego </ul>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.