Postado em 18 de novembro de 2011 por Henderson | Categorias: Úteis | Tags: Paginação | 1 Comentário » | Comentar
Coloque o código abaixo no arquivo functions.php do seu tema:
//////////////////////////////////////////////////////////////////////////
/// FUNCAO PARA FAZER PAGINAÇÃO /////
////////////////////////////////////////////////////////////////////////
function wp_corenavi() {
global $wp_query, $wp_rewrite;
$pages = '';
$max = $wp_query->max_num_pages;
if (!$current = get_query_var('paged')) $current = 1;
$a['base'] = str_replace(999999999, '%#%', get_pagenum_link(999999999));
$a['total'] = $max;
$a['current'] = $current;
$total = 1; //1 - display the text "Page N of N", 0 - not display
$a['mid_size'] = 5; //how many links to show on the left and right of the current
$a['end_size'] = 1; //how many links to show in the beginning and end
$a['prev_text'] = '« Anterior'; //text of the "Previous page" link
$a['next_text'] = 'Próxima »'; //text of the "Next page" link
if ($max > 1) echo '<div>';
if ($total == 1 && $max > 1) $pages = '<span>Página ' . $current . ' de ' . $max . '</span>'."\r\n";
echo $pages . paginate_links($a);
if ($max > 1) echo '</div>';
}
Para ativar a função nas páginas que devem entrar a páginação coloque o código abaixo:
if (function_exists('wp_corenavi')) wp_corenavi();
Postado em 12 de maio de 2011 por Henderson | Categorias: Loop no Wordpress, Paginação | Tags: Paginação | Sem comentários » | Comentar
Para colocar páginação no WordPress use a query abaixo, onde o parametro posts_per_page é igual a quantidade de posts por página:
<?php query_posts( 'posts_per_page=5&paged=' . get_query_var( 'paged' ) ); ?>
Para colocar os botões de navegação use o código abaixo entre o endwhile e o endif do loop:
<div class="btn-arr fl"><?php next_posts_link('« Página Anterior') ?></div>
<div class="btn-arr fr"><?php previous_posts_link('Próxima página »') ?></div>
Modelo de CSS:
/*BOTOES NAVEGACAO*/
.btn-arr {
margin-top: -10px;
margin-bottom: 10px;
}
.btn-arr a{
font-weight: 600;
color:#DE7047;
}
.fl {
float: left;
}
.fr {
float: right;
margin-right: 25px;
}
Exemplo:
<?php query_posts( 'posts_per_page=5&paged=' . get_query_var( 'paged' ) ); ?>
<?php //query_posts('showposts=3'); ?>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post() ?>
<div id="post-<?php the_ID(); ?>" style="margin-bottom: 20px; border-bottom: 1px solid #4A4A4A; padding-bottom: 20px;">
<h2><?php the_title(); ?></h2>
<div>
<?php the_content(); ?>
</div>
<div><?php comments_popup_link('Comente!', '(1) Comentário', '(%) Comentários'); ?></div>
<div><?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) { ADDTOANY_SHARE_SAVE_KIT(); } ?></div>
</div>
<!--/post-->
<?php endwhile;?>
<div><?php next_posts_link('« Página Anterior') ?></div>
<div><?php previous_posts_link('Próxima página »') ?></div>
<br />
<?php endif; ?>
Outro modelo de Query:
<?php $featured_query = new WP_Query("orderby=date&order=desc&posts_per_page=6&paged=" . get_query_var( 'paged' )); $contador_posts = 1; ?>
<?php while ($featured_query->have_posts()) : $featured_query->the_post(); ?>