category-membres.php 7.99 KB
Newer Older
N. Peraldi's avatar
N. Peraldi committed
1
<?php
2
//nombre max de membres 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
/**On affiche les boutons pour trier les membres en fonction du type de collectivité
 * @param string $category_to_select
 */
function childrens_of_member_category($category_to_select)
{
    $member_category_object = get_category_by_slug("membres");

    $id = $member_category_object->cat_ID;
    $server_link = $_SERVER["SERVER_NAME"];
    $link_Category = "http://" . $server_link . "/category/";
    $current_category = $category_to_select;

    dump_debug($_SERVER);
    echo_debug("\n----------------------\n");
    dump_debug($member_category_object);

    $childrens = get_term_children($id, "category"); //contiendra les id de tous les enfants de adhérent

    if ($current_category == "membres" || $current_category == "") {
        echo " <li class='adullact-sort-button adullact-selected'><a href='" . $link_Category . "membres/'>Tout</a></li>";
    } else {
        echo " <li class='adullact-sort-button'><a href='" . $link_Category . "membres/'>Tout</a></li>";
    }

    foreach ($childrens as $c) {
        $temp_category = get_category($c); //objet contenant les infos de la catégorie enfant

        $my_link = "<li class='adullact-sort-button";

        if ($temp_category->slug == $category_to_select) {
            //si on est en train d'afficher la catégorie sélectionnée
            $my_link .= " adullact-selected";
        } else {
            echo_debug($temp_category->slug . "=/=" . $category_to_select);
        }

        $my_link .= "'><a href = \"http://" . $server_link . "/category/";
        $my_link .= $temp_category->slug;
        $my_link .= "\"";

        $my_link .= "\">";
        $my_link .= $temp_category->name;
        $my_link .= "</a></li>";

        echo $my_link;
    }
}

/**on génère les boutons pour trier les membres par ordre croissant / décroissant
 * @param string $order
 * @param string $page
 * @param string $link
 */
function sort_page($order, $page, $link)
{
    $for_asc_link = $link . "?page=" . $page . "&order=asc";
    $for_desc_link = $link . "?page=" . $page . "&order=desc";
    if ($order == "desc") {
        ?>
        <li class="adullact-sort-button">
            <a href="<?php echo $for_asc_link; ?>">
                Croissant
            </a>
        </li>
        <li class="adullact-sort-button adullact-selected">
            <a href="<?php echo $for_desc_link; ?>">
                Décroissant
            </a>
        </li>
        <?php
    } else {
        ?>
        <li class="adullact-sort-button adullact-selected">
            <a href="<?php echo $for_asc_link; ?>">
                Croissant
            </a>
        </li>
        <li class="adullact-sort-button">
            <a href="<?php echo $for_desc_link; ?>">
                Décroissant
            </a>
        </li>

        <?php
    }
}
N. Peraldi's avatar
N. Peraldi committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//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
112
113
114
get_header();
$min_member_numero = 1 + ($page * $maxMembersPerPage) - $maxMembersPerPage;
$max_member_numero = ($page * $maxMembersPerPage);
N. Peraldi's avatar
N. Peraldi committed
115
?>
116
    <div class="wrap adullact-no-height-padding">
N. Peraldi's avatar
N. Peraldi committed
117
        <main id="main" class="site-main" role="main">
N. Peraldi's avatar
N. Peraldi committed
118
119
120
121
122
            <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
123
                        $url = explode("/", $_SERVER["REDIRECT_URL"]);
N. Peraldi's avatar
N. Peraldi committed
124

N. Peraldi's avatar
N. Peraldi committed
125
126
127
128
129
                        //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
130
                            $number_of_words -= 1;
N. Peraldi's avatar
N. Peraldi committed
131
                        }
N. Peraldi's avatar
N. Peraldi committed
132
133
                        $category = $url[$number_of_words - 1];
                        childrens_of_member_category($category);
N. Peraldi's avatar
N. Peraldi committed
134
135
136
137
138
139

                        ?>
                    </ul>
                </div>
                <div id="adullact-sort-by-name">
                    <ul class="adullact-member-list">
N. Peraldi's avatar
N. Peraldi committed
140
                        <?php sort_page($order, $page, $link) ?>
N. Peraldi's avatar
N. Peraldi committed
141
142
143
                    </ul>
                </div>
            </div>
144

N. Peraldi's avatar
N. Peraldi committed
145
146
147
148
149
150
151
152
                <?php
                $args = array(
                    "post_type" => "page",
                    "order" => $order,
                    "category_name" => $category,
                    "orderby" => "title",
                    "posts_per_page" => -1);
                $mypages = get_posts($args);
N. Peraldi's avatar
N. Peraldi committed
153

N. Peraldi's avatar
N. Peraldi committed
154
155
                $number_of_total_posts = count($mypages); //pour les pages
                if (($number_of_total_posts == 0) || ($number_of_total_posts < $min_member_numero)) {
156
                    echo "<h3 class='adullact-blue'>Aucun résultat.</h3>";
N. Peraldi's avatar
N. Peraldi committed
157
158
                    $pagination = false;
                } else {
159
160
                    echo "<h3 class='adullact-blue adullact-no-padding'>" . $number_of_total_posts . " résultats</h3>";
                    echo "<div class='adullact-members-list'>";
N. Peraldi's avatar
N. Peraldi committed
161
162
163
164
165
166
                    $counter = 1;
                    foreach ($mypages 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];
N. Peraldi's avatar
N. Peraldi committed
167

N. Peraldi's avatar
N. Peraldi committed
168
169
170
171
172
173
174
                                ?>
                                <div class="adullact-member">
                                    <div>
                                        <a href="<?php echo $url; ?>" target="_blank">
                                            <?php the_post_thumbnail(array("200", "200")); ?> <br>
                                        </a>
                                    </div>
N. Peraldi's avatar
N. Peraldi committed
175

N. Peraldi's avatar
N. Peraldi committed
176
                                    <p><?php the_title(); ?></p><br>
N. Peraldi's avatar
N. Peraldi committed
177
                                </div>
N. Peraldi's avatar
N. Peraldi committed
178
179
                                <?php
                            } else {
180
                                //on a dépassé le nombre max de membres à afficher, on peut donc stopper la boucle car elle n'affichera plus rien.
N. Peraldi's avatar
N. Peraldi committed
181
182
                                break;
                            }
N. Peraldi's avatar
N. Peraldi committed
183
                        }
N. Peraldi's avatar
N. Peraldi committed
184
185
                        $counter += 1;
                    endforeach;
186
187
188
                    ?>
                    </div>
                    <?php
N. Peraldi's avatar
N. Peraldi committed
189
190
                    wp_reset_postdata();
                }
N. Peraldi's avatar
N. Peraldi committed
191

N. Peraldi's avatar
N. Peraldi committed
192
193
194
195
                if ($pagination) {
                    ?>
                    <div class="pagination">
                        <?php
N. Peraldi's avatar
N. Peraldi committed
196

N. Peraldi's avatar
N. Peraldi committed
197
198
                        $number_of_pages_to_generate = intdiv($number_of_total_posts, $maxMembersPerPage);
                        $reste = $number_of_total_posts % $maxMembersPerPage;
N. Peraldi's avatar
N. Peraldi committed
199

N. Peraldi's avatar
N. Peraldi committed
200
201
202
                        if ($reste > 0) {
                            $number_of_pages_to_generate += 1;
                        }
N. Peraldi's avatar
N. Peraldi committed
203

N. Peraldi's avatar
N. Peraldi committed
204
205
206
207
208
209
210
211
212
                        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
213
214
                        }
                        ?>
N. Peraldi's avatar
N. Peraldi committed
215
216
                    </div>
                <?php } ?>
N. Peraldi's avatar
N. Peraldi committed
217
        </main>
218
219
    </div>
<?php get_footer(); ?>