category-21.php 2.04 KB
Newer Older
root's avatar
root committed
1 2
<?php

root's avatar
root committed
3
//nombre de membres à afficher par ligne
root's avatar
root committed
4 5
$maxMembersPerLine = 3;

root's avatar
root committed
6 7 8
get_header();

?>
Nathan Peraldi's avatar
Nathan Peraldi committed
9 10 11 12
    <ul>
        <?php
        global $post; //variable wp
        $order = "asc";
root's avatar
root committed
13

Nathan Peraldi's avatar
Nathan Peraldi committed
14 15
        //on récup l'id de la catégorie de l'url
        $currentCategoryID = explode("=", $_SERVER['REQUEST_URI'])[1];
root's avatar
root committed
16

Nathan Peraldi's avatar
Nathan Peraldi committed
17 18
        //et on récup le nom à partir de l'id
        $category = get_the_category_by_id($currentCategoryID);
root's avatar
root committed
19

Nathan Peraldi's avatar
Nathan Peraldi committed
20 21 22
        //il se peut que l'id de la catégorie ne soit pas précisée dans l'url et get_the_category retourne un tableau d'erreurs.
        if (gettype($category) == "object") {
            $category = "Adhérent";
root's avatar
root committed
23
        }
root's avatar
root committed
24

Nathan Peraldi's avatar
Nathan Peraldi committed
25 26 27
        //on récup le tri croissant / décroissant
        if (isset($_GET["order"])) {
            $order = $_GET["order"];
root's avatar
root committed
28

Nathan Peraldi's avatar
Nathan Peraldi committed
29 30 31
            if ($order != "asc" && $order != "desc") {
                $order = "asc";
            }
root's avatar
root committed
32
        }
Nathan Peraldi's avatar
Nathan Peraldi committed
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
        $args = array('posts_per_page' => 10, 'offset' => 0, 'cat' => $currentCategoryID, 'orderby' => 'title', 'order' => $order);

        $myposts = get_posts($args);
        echo "<br>";

        $count = 0; //va servir pour les retour à la ligne lorsqu'on a affiché le max d'éléments par ligne
        childrens_of_member_category($category);
        echo "<div class='adullact-members-list'>";

        echo "<div class='adullact-line'>";
        foreach ($myposts as $post) : setup_postdata($post);
            $id = get_the_id();
            $url = get_metadata("post", $id, "project_url")[0];
            $count += 1;
            ?>

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

            <?php
            if ($count >= $maxMembersPerLine) {
                $count = 0;
                echo "</div>";
                echo "<div class='adullact-line'>";
            }

        endforeach;
        echo "</div></div>";

        wp_reset_postdata(); ?>
    </ul>
67
<?php get_footer(); ?>