category-adherent.php 4.71 KB
Newer Older
1 2
<?php
//nombre max d'adhérents par page
3 4
$maxMembersPerPage = 20;

5 6
$page = 1;
$order = "asc";
7 8
$link = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER["REDIRECT_URL"];
$pagination = true;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

//on vérifie bien le numéro de la page
if (isset($_GET["page"])) {
    if (is_numeric($_GET["page"])) {
        if (($_GET["page"] > 0) && ($_GET["page"] < 100)) {
            $page = $_GET["page"];
        }
    }
}

//on vérifie bien l'ordre donné
if (isset($_GET["order"])) {
    if ($_GET["order"] == "desc") {
        $order = "desc";
    }
}

26 27 28
get_header();
$min_member_numero = 1 + ($page * $maxMembersPerPage) - $maxMembersPerPage;
$max_member_numero = ($page * $maxMembersPerPage);
29
?>
30
    <div class="wrap">
31
        <main id="main" class="site-main" role="main">
Nathan Peraldi's avatar
Nathan Peraldi committed
32 33 34 35 36
            <div id="adullact-sort-buttons">
                <div id="adullact-sort-by-type-buttons">
                    <ul class="adullact-member-list">
                        <?php
                        global $post; //variable wp
37
                        $url = explode("/", $_SERVER["REDIRECT_URL"]);
38

39 40 41 42 43
                        //nombre de mots dans l'url, sert à déterminer la catégorie recherchée
                        $number_of_words = count($url);
                        if ($url[$number_of_words - 1] == "") {
                            unset($url[$number_of_words - 1]);
                            $url = array_values($url);
44
                            $number_of_words -= 1;
Nathan Peraldi's avatar
Nathan Peraldi committed
45
                        }
46 47
                        $category = $url[$number_of_words - 1];
                        childrens_of_member_category($category);
Nathan Peraldi's avatar
Nathan Peraldi committed
48 49 50 51 52 53

                        ?>
                    </ul>
                </div>
                <div id="adullact-sort-by-name">
                    <ul class="adullact-member-list">
54
                        <?php sort_page($order, $page, $link) ?>
Nathan Peraldi's avatar
Nathan Peraldi committed
55 56 57 58
                    </ul>
                </div>
            </div>
            <?php echo "<div class='adullact-members-list'>";
59
            $args = array('posts_per_page' => -1, 'offset' => "0", 'category_name' => $category, 'orderby' => 'title', 'order' => $order);
60
            $myposts = get_posts($args);
61

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
            $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];

                            ?>
                            <div class="adullact-member">
                                <div>
                                    <a href="<?php echo $url; ?>" target="_blank">
                                        <?php the_post_thumbnail(array("200", "200")); ?> <br>
                                    </a>
                                </div>

                                <p><?php the_title(); ?></p><br>
                            </div>
                            <?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();
            }

            if ($pagination) {
97
                ?>
98 99 100 101 102 103 104 105 106
                <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;
                    }
Nathan Peraldi's avatar
Nathan Peraldi committed
107

108 109 110 111 112 113 114 115 116 117 118
                    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
                    }
                    ?>
Nathan Peraldi's avatar
Nathan Peraldi committed
119
                </div>
120
            <?php } ?>
121
        </main>
122 123
    </div>
<?php get_footer(); ?>