category-28.php 2.05 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
get_header();

?>

N. Peraldi's avatar
N. Peraldi committed
10
    <ul>
root's avatar
root committed
11

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

N. Peraldi's avatar
N. Peraldi committed
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

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

N. Peraldi's avatar
N. Peraldi committed
22 23 24
        //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";
25
        }
26

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

N. Peraldi's avatar
N. Peraldi committed
31 32 33
            if ($order != "asc" && $order != "desc") {
                $order = "asc";
            }
root's avatar
root committed
34
        }
N. Peraldi's avatar
N. Peraldi committed
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
        $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>
<?php get_footer(); ?>