Nesil Kutu Harf
Labs WP Tricks

Single.php for Custom Post Types

Merhaba, Kısaca açıklayacak olursak, single.php dosyanız var ve örnek olarak twenty_twelve temasını incelediğinizde: get_template_part( ‘template-parts/content’, get_post_format() ); şeklinde wordpress in sunduğu alıntı, link, .. yazı formatlarından hangisi seçili ise ona…

Me
Hakkı Cengiz ☙ 1 dk okuma süresi
☙ 12 Ağu 2020 ☙ 1.686

Merhaba,
Kısaca açıklayacak olursak, single.php dosyanız var ve örnek olarak twenty_twelve temasını incelediğinizde: get_template_part( 'template-parts/content', get_post_format() ); şeklinde wordpress in sunduğu alıntı, link, .. yazı formatlarından hangisi seçili ise ona göre single php içinde contentinizi çekebiliyoruz. İş custom post type a geldiğinde biraz ellerimizi çalıştırmamız gerekiyor. Bu yüzden aşağıdaki kodu eklediğimizde post type 'post' değilse bizim oluşturduğumuz post_type ı kolaylıkla çağırabiliriz.

  1. WordPress Custom Post Type Single Çağırma

    
    <?php
    get_header();
    
    while ( have_posts() ) :
        the_post();
    
        if ( !('post' == get_post_type() ) ) {
            get_template_part( 'template-parts/content', get_post_type() );
        } else {
            get_template_part( 'template-parts/content', get_post_format() );
        }
    
    endwhile; // End of the loop.
    
    get_footer();
    ?>
    
  2. Bonus: Script & Style Dosyalarını Özel Olarak Dahil Etmek İçin;

    
    if ( is_single() && 'custom_post_type' == get_post_type() ) {
      //
    }
    
0 0 votes
Article Rating
Subscribe
Bildir
guest

0 Yorum
Eskiler
En Yeniler Beğenilenler
Inline Feedbacks
View all comments
  • Panel 1
  • Panel 2
  • Panel 3
  • Panel 4
Welcome!
0
Would love your thoughts, please comment.x