Commit ab271ae9 authored by Nathan Peraldi's avatar Nathan Peraldi

add pagination functionality

parent 8aebc9b8
<?php
//nombre max d'adhérents par page
$maxMembersPerPage = "30";
$maxMembersPerPage = 20;
$page = 1;
$order = "asc";
$link = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER["REDIRECT_URL"];
$pagination = true;
//on vérifie bien le numéro de la page
if (isset($_GET["page"])) {
......@@ -19,14 +22,15 @@ if (isset($_GET["order"])) {
$order = "desc";
}
}
get_header();
get_header();
$min_member_numero = 1 + ($page * $maxMembersPerPage) - $maxMembersPerPage;
$max_member_numero = ($page * $maxMembersPerPage);
?>
<div class="wrap">
<main id="main" class="site-main" role="main">
<div id="adullact-sort-buttons">
<div id="adullact-sort-by-type-buttons">
<ul class="adullact-member-list">
<?php
global $post; //variable wp
......@@ -37,9 +41,8 @@ get_header();
if ($url[$number_of_words - 1] == "") {
unset($url[$number_of_words - 1]);
$url = array_values($url);
$number_of_words-=1;
$number_of_words -= 1;
}
$category = $url[$number_of_words - 1];
childrens_of_member_category($category);
......@@ -48,18 +51,26 @@ get_header();
</div>
<div id="adullact-sort-by-name">
<ul class="adullact-member-list">
<?php sort_page($order,$page) ?>
<?php sort_page($order, $page, $link) ?>
</ul>
</div>
</div>
<?php echo "<div class='adullact-members-list'>";
$args = array('posts_per_page' => -1, 'offset' => 0, 'category_name' => $category, 'orderby' => 'title', 'order' => $order);
$args = array('posts_per_page' => -1, 'offset' => "0", 'category_name' => $category, 'orderby' => 'title', 'order' => $order);
$myposts = get_posts($args);
$number_of_total_posts = count($myposts); //pour les pages
if (($number_of_total_posts == 0) || ($number_of_total_posts < $min_member_numero)) {
echo "<h3>Aucun résultat.</h3>";
$pagination = false;
} else {
$counter = 1;
foreach ($myposts as $post) : setup_postdata($post);
if ($counter >= $min_member_numero) {
if ($counter <= $max_member_numero) {
$id = get_the_id();
$url = get_metadata("post", $id, "project_url")[0];
$count += 1;
?>
<div class="adullact-member">
<div>
......@@ -70,9 +81,43 @@ get_header();
<p><?php the_title(); ?></p><br>
</div>
<?php endforeach;
<?php
} else {
//on a dépassé le nombre max d'adhérents à afficher, on peut donc stopper la boucle car elle n'affichera plus rien.
break;
}
}
$counter += 1;
endforeach;
echo "</div></div>";
wp_reset_postdata(); ?>
wp_reset_postdata();
}
if ($pagination) {
?>
<div class="pagination">
<?php
$number_of_pages_to_generate = intdiv($number_of_total_posts, $maxMembersPerPage);
$reste = $number_of_total_posts % $maxMembersPerPage;
if ($reste > 0) {
$number_of_pages_to_generate += 1;
}
for ($i = 1; $i <= $number_of_pages_to_generate; $i++) {
$page_link = $link . "?page=" . $i . "&order=" . $order;
$link_class = "adullact-page-link";
if ($page == $i) {
$link_class .= " adullact-page-link-selected";
}
?>
<a href="<?php echo $page_link ?>" class="<?php echo $link_class ?>"><?php echo $i ?></a>
<?php
}
?>
</div>
<?php } ?>
</main>
</div>
<?php get_footer(); ?>
\ No newline at end of file
......@@ -4,7 +4,6 @@ add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles');
function my_theme_enqueue_styles()
{
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
}
$debug_functions = false;
......@@ -73,16 +72,13 @@ function childrens_of_member_category($category_to_select)
echo $my_link;
}
}
function sort_page($order, $page)
function sort_page($order, $page,$link)
{
$link = $_SERVER['REQUEST_URI'];
$for_asc_link = $link . "?page=" . $page . "&order=asc";
$for_desc_link = $link . "?page=" . $page . "&order=desc";
if ($order = "desc") {
if ($order == "desc") {
?>
<li class="adullact-sort-button">
<a href="<?php echo $for_asc_link; ?>">
......@@ -111,5 +107,3 @@ function sort_page($order, $page)
<?php
}
}
\ No newline at end of file
?>
\ No newline at end of file
......@@ -15,7 +15,7 @@
@media screen and ( min-width: 67em ) {
.wrap {
max-width: 1200px;
padding:28px;
padding: 28px;
}
.navigation-top .wrap {
......@@ -28,8 +28,8 @@
/*************************************************************/
#adullact-sort-buttons {
display:flex;
flex-direction:row;
display: flex;
flex-direction: row;
}
.adullact-members-list {
......@@ -133,15 +133,25 @@
margin: 7px;
}
#adullact-sort-by-type-buttons
{
width:70%;
#adullact-sort-by-type-buttons {
width: 70%;
}
#adullact-sort-by-name {
padding-left: 2%;
}
#adullact-sort-by-name{
padding-left:2%;
.adullact-page-link {
padding: 8px 12px;
background-color: aliceblue;
margin: 3px;
}
.adullact-page-link-selected {
background-color: #4891bf;
}
/*************************************************************/
/*Formulaire d'adhésion*/
/*************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment