Bonjour,
Ma configuration WP actuelle
- Version de PHP/MySQL : PHP : 5.6.19/ MySQL : 5.7.11
- Thème utilisé : Perso
- Extensions en place : ACF et CPT UI
- Nom de l’hébergeur : Local
- Adresse du site : Local
Problème(s) rencontré(s) :
J’essai d’implémenter un système de pagination dans mon thème wordpress, lorsque je clic sur page suivante j’ai bien mon URL qui change : « …/actualite/page/2 » mais je suis redirigé sur index.php.
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => 'actualite',
'posts_per_page' => 2,
'paged' => $paged
);
$the_query = new WP_Query( $query_args );
La query
if (function_exists(custom_pagination)) {
custom_pagination($the_query->max_num_pages,"",$paged);
}
L'exécution
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 "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
}
Le fichier function.php