<?php include("_ayarlar.php"); ?>
<?php include("_fonksiyonlar.php"); ?>
<?php include("_header.php"); ?>
	    <!-- Start retroy layout blog posts -->
        <section class="section bg-light">
        <div class="container">
            <div class="col-12">
                <div class="heading text-center"><?php
                    $kategori_id = $_GET["id"];
                    $sql = "SELECT * FROM kategori WHERE kategori_id = '$kategori_id' ";
                    $tablo = $vt->query($sql);
                    $satir = $tablo->fetch_assoc();
                    echo $satir["kategori_ad"];
                ?></div>
            </div>
        <div id="carouselExampleDark" class="carousel carousel-dark slide">
            <div class="carousel-indicators">

                <?php

                    for ($i=0; $i<2 ; $i++) { 
                        if($i==0) echo "<button type='button' data-bs-target='#carouselExampleDark' data-bs-slide-to='$i' class='active' aria-current='true' aria-label='Slide $i'></button>";
                        else echo "<button type='button' data-bs-target='#carouselExampleDark' data-bs-slide-to='$i' aria-label='Slide $i'></button>";
                    }

                ?>

            </div>
            <div class="carousel-inner">            
                <?php
                $kontrol = 0;
                
                $sql = "SELECT * FROM haber WHERE kategori = '$kategori_id' ORDER BY id DESC LIMIT 2";
                $tablo = $vt->query($sql);
                while($satir = $tablo->fetch_assoc()){
                    if ($kontrol == 0) {
                        echo "<div class='carousel-item active' data-bs-interval='2000'>";
                    } else {
                        echo "<div class='carousel-item' data-bs-interval='2000'>";
                    }
                    echo '<a href="haber.php?id='.$satir['id'].'&baslik='.baslik_donustur($satir['baslik']).'">
                        <img src="kapak/'.$satir['kapak'].'" class="d-block w-100" style="height: 400px; object-fit: cover;" alt="...">
                        <div class="carousel-caption d-none d-md-block">
                            <h5 style="background-color:white">'.$satir['baslik'].'</h5>
                        </div>
                        </a>
                    </div>';  
                    $kontrol++;                  
                }
                ?>
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="visually-hidden">Previous</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="visually-hidden">Next</span>
            </button>
            </div>
        </div>
    </section>
    <!-- End retroy layout blog posts -->

    <!-- Start posts-entry -->
    <section class="section">
        <div class="container">
            <div class="row">
                <?php
                $sql = "SELECT * FROM haber INNER JOIN kategori ON haber.kategori = kategori.kategori_id WHERE kategori = '$kategori_id' ORDER BY id DESC LIMIT 2,9";
                $tablo = $vt->query($sql);
                while($satir = $tablo->fetch_assoc()){ # Haber tablosunda kayıt olduğu sürece
                ?>
                <div class="col-lg-4 mb-4">
                    <div class="post-entry-alt">
                        <a href="haber.php?id=<?php echo $satir['id'] ?>&baslik=<?php echo baslik_donustur($satir['baslik']) ?>" class="img-link"><img src="kapak/<?php echo $satir['kapak'] ?>" alt="Image"
                            class="img-fluid rounded" style="background-size: cover; height: 300px; object-fit: cover;"></a>
                        <div class="excerpt">
                            <h2><a href="haber.php?id=<?php echo $satir['id'] ?>&baslik=<?php echo baslik_donustur($satir['baslik']) ?>"><?php echo $satir['baslik'] ?></a></h2>
                            <div class="post-meta align-items-center text-left clearfix">
                                
                                <span><?php echo tarih_donustur($satir['eklenme_tarihi']) ?></span>
                            </div>
                            <?php echo implode(' ', array_slice(explode(' ', $satir['icerik']), 0, 20)) ?>...
                            <p><a href="haber.php?id=<?php echo $satir['id'] ?>&baslik=<?php echo baslik_donustur($satir['baslik']) ?>" class="read-more">Okumaya Devam Et</a></p>
                        </div>
                    </div>
                </div>
                <?php
                }
                ?>
            </div>

        </div>
    </section>
<?php include("_footer.php"); ?>