• 17-05-2009, 13:36:14
    #1
    Merhaba,

    Tekil yazı sayfasında şöyle bir sorgu çalıştırmak istiyorum :

    "Eğer, yazı ıdsi 8'se şu kod, yazı ıdsi 5'se şu kod aktifleşsin"

    Codex'te aradım biraz ama, bulamadım malesef.

    Teşekkürler.
  • 17-05-2009, 14:59:31
    #2
    if ( is_single('8') ) {
    //kodunuz
    }

    if ( is_single('5') ) {
    //kodunuz
    }

    Kaynak
  • 17-05-2009, 15:45:38
    #3
    Alıntı
    <?php
    // Get $post if you're inside a function
    global $post;

    if ( is_single('63') ) {
    //
    <div class="adsense-post">


    <ul>

    <?php
    global $post;
    $myposts = get_posts('numberposts=5&offset=1&category=187');
    foreach($myposts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>


    </div>
    }

    ?>
    olarak ekledim direk tekil yazıya,

    Alıntı
    Parse error: syntax error, unexpected '<' in /home/**domains/***/public_html/wp-content/themes/*** on line 56
    hatası verdi malesef.
  • 17-05-2009, 16:57:56
    #4
    Alıntı
    <?php
    // Get $post if you're inside a function
    global $post;

    if ( is_single('63') ) {
    //
    <div class="adsense-post">


    <ul>

    <?php
    global $post;
    $myposts = get_posts('numberposts=5&offset=1&category=187');
    foreach($myposts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>


    </div>
    }

    ?>
    Kodu yanlış olmuş. Doğrusu
    Alıntı
    <?php
    // Get $post if you're inside a function

    if ( is_single('63') ) {
    ?>
    <div class="adsense-post">
    <ul>
    <?php
    $myposts = get_posts('numberposts=5&offset=1&category=187');
    foreach($myposts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    </div>
    <?php
    }
    ?>
    PHP kodlarıyla html kodlarını birbirine karıştırmayın, php kodlarını kapadıktan sonra html kodlarını kullanmalısınız. Ayrıca eğer doğrudan single.php içerisinde kullanıyorsanız kodları global $post demeye gerek yok.
  • 17-05-2009, 17:31:17
    #5
    Hocam teşekkür ederim

    Elinize sağlık .
  • 17-05-2009, 18:06:33
    #6
    Yakup bunu kategorilerde yapmakta söz konusu olabilir mi ?

    Blogundan kod aldım. O koda göre tüm kategori sayfalarında sadece id'sini verdigim kategoriye ait alt kotegoriler listeleniyor. mesela desek ki

    if ( is_single('8') ) {
    //Buraya Listelenecek A kategorisi
    }

    if ( is_single('8') ) {
    //Buraya Listelenecek B kategorisi
    }

    if ( is_single('8') ) {
    //Buraya Listelenecek C kategorisi
    }

    Nasıl bir kod ortaya ?

    Aynı zamanda bu kodları arrchive.php dosyasında kullanacagız sanırım ?
  • 17-05-2009, 19:33:07
    #7
    Benzerini kategoriler için is_single yerine is_category fonksiyonunu, archive.php dosyasında kullanarak gerçekleştirebilirsiniz.
    Ayrıca eğer bir kategoriye tıklanmışsa bu kategorinin id'sini
    $kad_id = get_query_var('cat');
    if ($kat_id) {
    // kategoriyle ilgili ne derdiniz varsa onu yazın
    }
    koduyla alıp, kullanabilirsiniz.
  • 17-05-2009, 20:16:10
    #8
    Yakup senin bu alt kategoriler adı altında yazmıs oldugun eklentinin içerisinden su kodları aldım

    // The widget itself.
    function nk_cats_sub_cat_widget($args, $number = 1) {
      global $kat_id, $wp_query;
      extract($args);
      $options = get_option('widget_cats_sub_cat');
      $title = empty($options[$number]['title']) ? 'Kategori' : $options[$number]['title'];
      if (is_category()) {
        $cat_obj = $wp_query->get_queried_object();
        $kat_id = $cat_obj->parent;
        if ($kat_id == 0) $kat_id = $cat_obj->cat_ID;
      }  //is_cat
    
      $kat_id = intval($kat_id);
      $childs = get_category_children($kat_id, $before = ' ', $after = '');
      $catts = explode (' ', trim($childs));
      if ((count($catts)!=1)&&(is_numeric($catts[0]))) {
        echo $before_widget;
        echo $before_title . $title . $after_title;
        echo '<ul>';
        foreach($catts as $catt) {
          $catname = get_cat_name($catt);
          echo '<li><a href="'.get_category_link($catt).'" title="'.$catname.'">'.$catname.'</a></li>';
        }
        echo '</ul>';
        echo $after_widget;
      }
    } //end of function
    Kategori derdim sadece ana kategoriye girildiğin " siteadi.com/category/a " a kategorisine ait alt kategorileri listeletmek.

    Bunun için çalışan bir kod vermen mümkün mü ?

    Yayınlamıs oldugun eklenti sidebar da kullanmak için fakat ben bunu archive.php içerisinde aktif etmek istiyorum
  • 17-05-2009, 21:21:27
    #9
    Aşağıdaki kodları kendinize göre düzenleyin. Denemedim ancak çalışacağını düşünüyorum.

    <?php
      if (is_category()) {
        $cat_obj = $wp_query->get_queried_object();
        $kat_id = $cat_obj->parent;
        if ($kat_id == 0) {  //Eğer ana kategori ise
           $kat_id = $cat_obj->cat_ID; 
    
           echo '<ul>';
           wp_list_categories('child_of=' . $kat_id);
           echo '</ul>';
    
        }
      }  //is_category
    ?>