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

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

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

?>

<ul>

12
    <?php
13
    global $post; //variable wp
root's avatar
root committed
14 15
    $order = "asc";

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

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

22 23 24 25
    //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
26

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

root's avatar
root committed
31 32
        if ($order != "asc" && $order != "desc") {
            $order = "asc";
33 34
        }
    }
root's avatar
root committed
35
    $args = array('posts_per_page' => 10, 'offset' => 0, 'cat' => $currentCategoryID, 'orderby' => 'title', 'order' => $order);
36 37

    $myposts = get_posts($args);
root's avatar
root committed
38 39
    echo "<br>";

40 41
    $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);
root's avatar
root committed
42
    echo "<div class='adullact-members-list'>";
43

root's avatar
root committed
44
    echo "<div class='adullact-line'>";
45 46 47
    foreach ($myposts as $post) : setup_postdata($post);
        $id = get_the_id();
        $url = get_metadata("post", $id, "project_url")[0];
48
        $count += 1;
49
        ?>
root's avatar
root committed
50

root's avatar
root committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        <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>";

67
    wp_reset_postdata(); ?>
root's avatar
root committed
68 69 70

</ul>

71
<?php get_footer(); ?>
root's avatar
root committed
72 73 74 75 76 77