Bonjour,
Je viens ici car j'ai un petit souci pour mettre en place un système de pagination sur une page ou j'affiche mes articles. Voilà le code de ma page actu :
Voilà la fonction pour la pagination :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); } else { $paged = 1; } $args = array ( 'post_type' => 'post', 'showposts' => -1, 'posts_per_page' => 2, 'paged' => $paged ); $act = new WP_Query( $args ); ?> <article class="page-actu"> <h1>Actualités</h1> <?php while ( $act->have_posts() ) { $act->the_post(); ?> <div class="separe-actu"> <h2><?php echo get_the_title(); ?></h2> <p><?php echo the_content(); ?></p> </div> <?php } ?> <?php if (function_exists(custom_pagination)) { custom_pagination($act->max_num_pages,"",$paged); } ?> </article>
Je trouve pas d'ou viens l'erreur... J'ai quatre articles sur ma page.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 function custom_pagination($numpages = '', $pagerange = '', $paged='') { if (empty($pagerange)) { $pagerange = 2; } global $paged; if (empty($paged)) { $paged = 1; } if ($numpages == '') { global $wp_query; $numpages = $wp_query->max_num_pages; if(!$numpages) { $numpages = 1; } } $pagination_args = array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'total' => $numpages, 'current' => $paged, 'show_all' => False, 'end_size' => 1, 'mid_size' => $pagerange, 'prev_next' => True, 'prev_text' => __('<'), 'next_text' => __('>'), 'type' => 'plain', 'add_args' => false, 'add_fragment' => '' ); $paginate_links = paginate_links($pagination_args); if ($paginate_links) { echo "<nav class='custom-pagination'>"; echo $paginate_links; echo "</nav>"; } }
Merci d'avance pour l'aide !
Partager