• 07-01-2023, 00:13:07
    #1
    Merhabalar,

    Php ile foreach döngüsünden gelen menülere nasıl active class'ı verebilirim.

    Bu şekilde tüm sayfaları mı kontrol edebiliyorum, ayrıca admin panelinden üst menü elemanlarının tutulduğu tablo mevcut.

        if(isset($_GET['sayfa'])){
            $page = $_GET['sayfa'];
            switch($s){
                case 'contact';
                    require_once("includes/contact");
                    break;
                case 'about';
                    require_once("includes/about.php");
                    break;
                case 'blog';
                    require_once("includes/blog.php");
                    break;
    
            }
    Foreach döngü bu şekilde,

    <?php foreach ($mainMenu as $menu1) {
                $altMenu = $db->prepare("select * from header_menu where ust_id=:ust_id and dil=:dil and durum=:durum order by sira asc ");
                $altMenu->execute(array(
                    'ust_id' => $menu1['id'],
                    'dil' => $_SESSION['dil'],
                    'durum' => '1'
                ));
            ?>
                <li class="<?php if ($altMenu->rowCount() > '0') {
                                echo 'dropdown_menu';
                            } ?>">
                    <a <?php if ($menu1['url'] == !null) { ?>href="<?= $menu1['url'] ?>" <?php } else { ?>href="javascript:void(0" <?php } ?>><?= $menu1['baslik'] ?></a>
                    <?php if ($altMenu->rowCount() > '0') { ?>
                        <i class="caret_down"></i>
                    <?php } ?>
                    <?php if ($altMenu->rowCount() > '0') { ?>
                        <ul class="sub-menu">
                            <?php foreach ($altMenu as $menu2) {
                                $ucuncuMenu = $db->prepare("select * from header_menu where ust_id=:ust_id and dil=:dil and durum=:durum order by sira asc ");
                                $ucuncuMenu->execute(array(
                                    'ust_id' => $menu2['id'],
                                    'dil' => $_SESSION['dil'],
                                    'durum' => '1'
                                ));
                            ?>
                                <li>
                                    <a href="<?= $menu2['url'] ?>">
                                        <?= $menu2['baslik'] ?>
                                        <?php if ($ucuncuMenu->rowCount() > '0') { ?>
                                            <i class="fa fa-angle-right" aria-hidden="true"></i>
                                        <?php } ?>
                                    </a>
                                    <?php if ($ucuncuMenu->rowCount() > '0') { ?>
                                        <ul class="third-level-menu">
                                            <?php foreach ($ucuncuMenu as $menu3) { ?>
                                                <li>
                                                    <a href="<?= $menu3['url'] ?>">
                                                        <p>
                                                            <?= $menu3['baslik'] ?>
                                                        </p>
                                                    </a>
                                                </li>
                                            <?php } ?>
                                        </ul>
                                    <?php } ?>
                                </li>
                            <?php } ?>
                        </ul>
                    <?php } ?>
                </li>
            <?php } ?>
  • 07-01-2023, 00:15:46
    #2
    kreawich adlı üyeden alıntı: mesajı görüntüle
    Merhabalar,

    Php ile foreach döngüsünden gelen menülere nasıl active class'ı verebilirim.

    Bu şekilde tüm sayfaları mı kontrol edebiliyorum, ayrıca admin panelinden üst menü elemanlarının tutulduğu tablo mevcut.

        if(isset($_GET['sayfa'])){
            $page = $_GET['sayfa'];
            switch($s){
                case 'contact';
                    require_once("includes/contact");
                    break;
                case 'about';
                    require_once("includes/about.php");
                    break;
                case 'blog';
                    require_once("includes/blog.php");
                    break;
    
            }
    Foreach döngü bu şekilde,

    <?php foreach ($mainMenu as $menu1) {
                $altMenu = $db->prepare("select * from header_menu where ust_id=:ust_id and dil=:dil and durum=:durum order by sira asc ");
                $altMenu->execute(array(
                    'ust_id' => $menu1['id'],
                    'dil' => $_SESSION['dil'],
                    'durum' => '1'
                ));
            ?>
                <li class="<?php if ($altMenu->rowCount() > '0') {
                                echo 'dropdown_menu';
                            } ?>">
                    <a <?php if ($menu1['url'] == !null) { ?>href="<?= $menu1['url'] ?>" <?php } else { ?>href="javascript:void(0" <?php } ?>><?= $menu1['baslik'] ?></a>
                    <?php if ($altMenu->rowCount() > '0') { ?>
                        <i class="caret_down"></i>
                    <?php } ?>
                    <?php if ($altMenu->rowCount() > '0') { ?>
                        <ul class="sub-menu">
                            <?php foreach ($altMenu as $menu2) {
                                $ucuncuMenu = $db->prepare("select * from header_menu where ust_id=:ust_id and dil=:dil and durum=:durum order by sira asc ");
                                $ucuncuMenu->execute(array(
                                    'ust_id' => $menu2['id'],
                                    'dil' => $_SESSION['dil'],
                                    'durum' => '1'
                                ));
                            ?>
                                <li>
                                    <a href="<?= $menu2['url'] ?>">
                                        <?= $menu2['baslik'] ?>
                                        <?php if ($ucuncuMenu->rowCount() > '0') { ?>
                                            <i class="fa fa-angle-right" aria-hidden="true"></i>
                                        <?php } ?>
                                    </a>
                                    <?php if ($ucuncuMenu->rowCount() > '0') { ?>
                                        <ul class="third-level-menu">
                                            <?php foreach ($ucuncuMenu as $menu3) { ?>
                                                <li>
                                                    <a href="<?= $menu3['url'] ?>">
                                                        <p>
                                                            <?= $menu3['baslik'] ?>
                                                        </p>
                                                    </a>
                                                </li>
                                            <?php } ?>
                                        </ul>
                                    <?php } ?>
                                </li>
                            <?php } ?>
                        </ul>
                    <?php } ?>
                </li>
            <?php } ?>
    Selamlar şu şekilde yapacaksın. site.com/slug şeklinde gelen url ile menü'deki slug'ları karşılaştıracaksın. Eğer adres satırındaki slug ile menü'deki slug birbirine eşitse active classı ekleteceksin.
  • 07-01-2023, 00:18:31
    #3
    ibrahimfidan adlı üyeden alıntı: mesajı görüntüle
    Selamlar şu şekilde yapacaksın. site.com/slug şeklinde gelen url ile menü'deki slug'ları karşılaştıracaksın. Eğer adres satırındaki slug ile menü'deki slug birbirine eşitse active classı ekleteceksin.
    Deniyorum, teşekkür ederim.