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

N. Peraldi's avatar
N. Peraldi committed
5 6
$page = 1;
$order = "asc";
N. Peraldi's avatar
N. Peraldi committed
7 8
$link = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER["REDIRECT_URL"];
$pagination = true;
N. Peraldi's avatar
N. Peraldi committed
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";
    }
}

N. Peraldi's avatar
N. Peraldi committed
26 27 28
get_header();
$min_member_numero = 1 + ($page * $maxMembersPerPage) - $maxMembersPerPage;
$max_member_numero = ($page * $maxMembersPerPage);
N. Peraldi's avatar
N. Peraldi committed
29
?>
30
    <div class="wrap">
N. Peraldi's avatar
N. Peraldi committed
31
        <main id="main" class="site-main" role="main">
N. Peraldi's avatar
N. 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
N. Peraldi's avatar
N. Peraldi committed
37
                        $url = explode("/", $_SERVER["REDIRECT_URL"]);
N. Peraldi's avatar
N. Peraldi committed
38

N. Peraldi's avatar
N. Peraldi committed
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);
N. Peraldi's avatar
N. Peraldi committed
44
                            $number_of_words -= 1;
N. Peraldi's avatar
N. Peraldi committed
45
                        }
N. Peraldi's avatar
N. Peraldi committed
46 47
                        $category = $url[$number_of_words - 1];
                        childrens_of_member_category($category);
N. Peraldi's avatar
N. Peraldi committed
48 49 50 51 52 53

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

N. Peraldi's avatar
N. Peraldi committed
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) {
N. Peraldi's avatar
N. Peraldi committed
97
                ?>
N. Peraldi's avatar
N. Peraldi committed
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;
                    }
N. Peraldi's avatar
N. Peraldi committed
107

N. Peraldi's avatar
N. Peraldi committed
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
                    }
                    ?>
N. Peraldi's avatar
N. Peraldi committed
119
                </div>
N. Peraldi's avatar
N. Peraldi committed
120
            <?php } ?>
N. Peraldi's avatar
N. Peraldi committed
121
        </main>
122 123
    </div>
<?php get_footer(); ?>