CloudBT CloudBT
  • 20-04-2022, 17:41:56
    #1
    Bu işlem query_posts ile yapılıyor sanıyordum değilmiş. ID'si 5 olan kategorideki son 5 gönderiyi anasayfamda göstermek istiyorum. Eklemem gereken PHP kodu nedir? Akışı bozmadan üste eklemek istiyorum.
  • 20-04-2022, 17:45:51
    #2
    query_posts olması lazım hocam.

    <?php if (is_home()) { query_posts("cat=1,2,3"); }
    ?>
    posts_per_page ile de yazı sayısı belirlenebilir diye düşünüyorum.
  • 20-04-2022, 17:50:40
    #3
    Merhaba ;
    Kod Başlangıcı
    <?php query_posts('showposts=10&orderby=date&cat=3,4,5'); ?>
    Üstte yer alan komutta
    showposts=10 kaç adet içerik listeleneceği
    date&cat=3 hangi kategoriden veri alınacağı

    Kod Bitişi
    <?php while (have_posts()) : the_post(); ?>
    Sorun olursa mesaj bırakın destek olurum...

    Papatyam Soft Yönetilebilir E-Ticaret Çözümleri
  • 20-04-2022, 17:51:30
    #4
    Misafir adlı üyeden alıntı: mesajı görüntüle
    query_posts olması lazım hocam.

    <?php if (is_home()) { query_posts("cat=1,2,3"); }
    ?>
    posts_per_page ile de yazı sayısı belirlenebilir diye düşünüyorum.
    Yok hocam query_posts ile yapınca sorun yaşıyorum, aradığım bu değil bu ana loop'a müdahale edip değiştiriyor. Mesela verdiğiniz kodu direk uyguladığımda ID'si 1,2,3 olan kategorileri göster diğerlerini gösterme demiş oluyorum ve akışa filtre uyguluyor. Ben bu kodu istemediğim kategorileri gizlemek için başına - ekleyerek kullanıyorum. Amacım tamamen ana akıştan bağımsız bir alanda çalışması. Sanırım aradığım şey WP_Query ama nasıl kullanacağım konusunda kafam karışık.
  • 20-04-2022, 17:52:35
    #5
        <?php query_posts('showposts=5&orderby=date&cat=1'); ?>
        <?php while (have_posts()) : the_post(); ?>
                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php endwhile; ?>
    Showpost ve date&cat kısımlarını kendinize göre düzenleyerek kullanabilirsiniz.
  • 20-04-2022, 18:37:00
    #6
    ByRecep77 adlı üyeden alıntı: mesajı görüntüle
    Merhaba ;
    Kod Başlangıcı
    <?php query_posts('showposts=10&orderby=date&cat=3,4,5'); ?>
    Üstte yer alan komutta
    showposts=10 kaç adet içerik listeleneceği
    date&cat=3 hangi kategoriden veri alınacağı

    Kod Bitişi
    <?php while (have_posts()) : the_post(); ?>
    Sorun olursa mesaj bırakın destek olurum...

    Papatyam Soft Yönetilebilir E-Ticaret Çözümleri
    profyko adlı üyeden alıntı: mesajı görüntüle
        <?php query_posts('showposts=5&orderby=date&cat=1'); ?>
        <?php while (have_posts()) : the_post(); ?>
                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php endwhile; ?>
    Showpost ve date&cat kısımlarını kendinize göre düzenleyerek kullanabilirsiniz.
    Anasayfada kullandığım tam olarak bu kodlar zaten, ben bunları düzenlemeden eklemek istiyorum. Daha detaylı anlatayım, while (have_posts()) : the_post(); ile bir anasayfam var ve query_posts kullandığımda buna müdahale ediyor, değiştiriyor, filtreliyor. İstediğim kesinlikle bu değil. Anasayfa yapmaya çalışmıyorum. Üste manşet alanı olarak belli bir kategoriyi göstermek istiyorum. Yani ayrı 2. bir bölüm olarak.
  • 20-04-2022, 18:56:19
    #7
    Kodları foruma ekleyemedim. Şuradan bakabilirsiniz.

    http://controlc.com/9e229663
  • 21-04-2022, 12:09:48
    #8
    FSahin adlı üyeden alıntı: mesajı görüntüle
    Kodları foruma ekleyemedim. Şuradan bakabilirsiniz.

    http://controlc.com/9e229663
    FSahin adlı üyeden alıntı: mesajı görüntüle
    Kodları foruma ekleyemedim. Şuradan bakabilirsiniz.

    http://controlc.com/9e229663
    Aynen hocam aradığım buydu, teşekkürler. Şöyle kullandım bir hatam varsa uyarır mısınız.

    Yaptığım alan:


    Kullandığım kodlar:
    echo '<div class="featured-content row">';
    
        // The Query
        $the_query = new WP_Query( array(
            'cat' => 3,
            'posts_per_page' => 1
        ) );
    
        // The Loop
        if ( $the_query->have_posts() ) {
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                echo '<div class="col-xs-6"><div class="grid-first">
                    <a href="'; the_permalink(); echo '" title="'; the_title_attribute(); echo'" rel="bookmark">';
                        the_post_thumbnail( 'featured-content-thumbnail-first' );
                    echo '</a>
                    <h2 class="overlay">';
                        the_title();
                    echo'</h2>
                </div></div>';
            }
        } else {
            // no posts found
        }
    
        // The Query
        $the_query = new WP_Query( array(
            'cat' => 3,
            'posts_per_page' => 4,
            'offset' => 1
        ) );
    
        echo '<div class="grid col-xs-6">';
            // The Loop
            if ( $the_query->have_posts() ) {
                while ( $the_query->have_posts() ) {
                    $the_query->the_post();
                    echo '<div class="col-xs-6">
                        <a href="'; the_permalink(); echo '" title="'; the_title_attribute(); echo'" rel="bookmark">';
                            the_post_thumbnail( 'featured-content-thumbnail' );
                        echo '</a>
                        <h2 class="overlay">';
                            the_title();
                        echo'</h2>
                    </div>';
                }
            }
        echo '</div>';
    
        /* Restore original Post Data */
        wp_reset_postdata();
    
    echo '</div>';