• 24-09-2022, 16:43:45
    #1
    Merhaba,

    Web sitesinde "sortit" fonksiyonunu kullanarak kategorilerde sıralama yapmaya çalışıyorum. 'Yeniden Eskiye' ve 'Eskiden Yeniye' fonksiyonunu kullanmaya çalışıyorum.

    Fonksiyon:

        function sortIt($sortType)
        {
        global $wp_query;
        $cat_ID = get_query_var('cat');
    
        if (strcmp($sortType, 'ASC') )
        {
            $newQuery = new WP_Query( array(
            'orderby' => 'date' ,
            'order'   => 'ASC',
            'cat' => $cat_ID,
            'posts_per_page' => '10') );
        }
    
        if (strcmp($sortType, 'DESC') )
        {
            $newQuery = new WP_Query( array(
            'orderby' => 'date' ,
            'order'   => 'DESC',
            'cat' => $cat_ID,
            'posts_per_page' => '10') );
        }
    
        return $newQuery;
        }
    Category.php'de menüye koyduğum kod:

                                        <li class="dropdown">
                                            <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Sırala</a>
                                            <ul class="dropdown-menu">
                                            <li class="nav-item"><a href="?sortby=asc" class="nav-link dropdown-item" type="button" role="tab">Yeniden Eskiye</a></li>
                                            <li class="nav-item"><a href="?sortby=desc" class="nav-link dropdown-item" type="button" role="tab">Eskiden Yeniye</a></li>
                                            </ul>
                                        </li>
    eğer url'de sortit varsa ona göre sırala yapmaya çalışıyorum.

    if-else yaparak, URL ile gönderileri ayıklamaya çalıştım.

    <?php if (is_page('?sortby=asc')) {
                              if ( $newQuery->have_posts() ) : while ( $newQuery->have_posts() ) : $newQuery->the_post();
                              } else { if (is_page('?sortby=desc')) {
                              if ( $newQuery->have_posts() ) : while ( $newQuery->have_posts() ) : $newQuery->the_post();
                              } } else { if (have_posts()) : while (have_posts()) : the_post();
                        } ?>
    Tabii bunu kapatmamız lazım, ancak kapatma kısmında hata olabilir.

                                        <?php endwhile; endif; ?>
    Aldığım hata: "Parse error: syntax error, unexpected '}' in "

    Yardımcı olabilecek var mı? Teşekkürler.
  • 24-09-2022, 17:16:26
    #2
    Pek anlamam ama sortby asc olan kodda 3 parantez açılmış 4 kapatılmış ondan olabilir
  • 24-09-2022, 17:56:07
    #3
    41Yazılım adlı üyeden alıntı: mesajı görüntüle
    Pek anlamam ama sortby asc olan kodda 3 parantez açılmış 4 kapatılmış ondan olabilir
    Cevabınız için teşekkürler,

    Kontrol ettim ama hepsi kapalı gözüküyor.
  • 24-09-2022, 18:59:59
    #4
    Sorunu çözdüm, belki işine yarayan olur;

    have_posts ve while açıldığı için ve aşağıda kapatıldığı için araya } sokulmaması gerekiyor. while ve ifi kapatmadan araya } sokmamak gerekiyor.

    <ul id="listPage" class="row item-list">
                                    <?php if (is_page(array('?sortby=asc', '?sortby=desc'))) { ?>
                                      <?php if ( $newQuery->have_posts() ) : while ( $newQuery->have_posts() ) : $newQuery->the_post(); ?>
                                        <li class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-4 column items-col">
                                            <div class="item">
                                                <a href="<?php the_permalink(); ?>" style="color: <?php echo $rl_category_color; ?>;" class="d-flex align-items-center">
                                                    <div class="in">
                                                        <div class="d-flex justify-content-between author">
                                                            <div class="author-name col-7">
                                                                <br><br>
                                                                <?php
                                                                    $author = get_post_meta( get_the_ID(), 'postAuthor', true );
                                                                    if(!empty($author)) {                                                      
                                                                        foreach ($author as $author_item => $item) {
                                                                            echo get_the_title($item).'<br>';
                                                                        }
                                                                    }
                                                                ?>
                                                            </div>
                                                            <div class="rank col-5 text-end">
                                                                <br><br>
                                                                <?php
                                                                    $konu = get_the_category( get_the_ID() );
                                                                    foreach ($konu as $item) {
                                                                        $konu_name = $item->name;
                                                                    }
                                                                    echo $konu_name;
                                                                ?>
                                                            </div>
                                                        </div>
                                                        <figure>
                                        <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_post_thumbnail_caption();?>" class="img-fit">
                                    </figure><br>
                                                        <div class="title"><?php echo title_limit(40); ?></div>
                                                        <p><?php echo icerik_limit(get_the_content(), 150); ?></p>
                                                    </div>
                                                </a>
                                            </div>
                                        </li>
                                        <?php endwhile; endif; } else if (have_posts()) : while (have_posts()) : the_post(); ?>
                                        <li class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-4 column items-col">
                                            <div class="item">
                                                <a href="<?php the_permalink(); ?>" style="color: <?php echo $rl_category_color; ?>;" class="d-flex align-items-center">
                                                    <div class="in">
                                                        <div class="d-flex justify-content-between author">
                                                            <div class="author-name col-7">
                                                                <br><br>
                                                                <?php
                                                                    $author = get_post_meta( get_the_ID(), 'postAuthor', true );
                                                                    if(!empty($author)) {                                                      
                                                                        foreach ($author as $author_item => $item) {
                                                                            echo get_the_title($item).'<br>';
                                                                        }
                                                                    }
                                                                ?>
                                                            </div>
                                                            <div class="rank col-5 text-end">
                                                                <br><br>
                                                                <?php
                                                                    $konu = get_the_category( get_the_ID() );
                                                                    foreach ($konu as $item) {
                                                                        $konu_name = $item->name;
                                                                    }
                                                                    echo $konu_name;
                                                                ?>
                                                            </div>
                                                        </div>
                                                        <figure>
                                        <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_post_thumbnail_caption();?>" class="img-fit">
                                    </figure><br>
                                                        <div class="title"><?php echo title_limit(40); ?></div>
                                                        <p><?php echo icerik_limit(get_the_content(), 150); ?></p>
                                                    </div>
                                                </a>
                                            </div>
                                        </li>
                                        <?php endwhile; endif; ?>