Diğer eğitim projelerimize baktınız mı ? KolayBiyoloji.com KolayFizik.com KolayMatematik.com
WordPress Tema single.php ve page.php ile Dinamik İçerik Sayfaları
🎯 Amaç
Bu derste:
- Tekil yazılar (
single.php) ve sayfalar (page.php) için özel şablonlar oluşturacağız. - Her yazıya tıklanınca detay sayfasında içeriği nasıl göstereceğimizi öğreneceğiz.
the_content(),comments_template()gibi fonksiyonları tanıyacağız.
📂 1. WordPress Şablon Hiyerarşisi Nedir?
WordPress, hangi dosyanın kullanılacağını otomatik olarak belirleyen bir sistem kullanır.
| İçerik Türü | Kullanılan Dosya |
|---|---|
| Tekil yazı | single.php |
| Sayfa | page.php |
| Kategori | category.php |
| Arama sonucu | search.php |
| Hiçbiri yoksa | index.php (yedek dosya) |
Yani bir yazıya tıkladığında WordPress önce single.php’yi arar, yoksa index.php‘yi kullanır.
🛠️ 2. single.php – Tekil Yazı Sayfası
Yeni bir dosya oluştur: single.php
<?php get_header(); ?>
<main class="single-post">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1><?php the_title(); ?></h1>
<p class="post-meta">
Yayınlanma Tarihi: <?php the_time('d F Y'); ?> | Kategoriler: <?php the_category(', '); ?>
</p>
<?php if (has_post_thumbnail()) : ?>
<div class="post-thumbnail">
<?php the_post_thumbnail('large'); ?>
</div>
<?php endif; ?>
<div class="post-content">
<?php the_content(); ?>
</div>
<div class="post-tags">
<?php the_tags('<strong>Etiketler:</strong> ', ', '); ?>
</div>
<section class="comments">
<?php comments_template(); ?>
</section>
</article>
<?php endwhile; endif; ?>
</main>
<?php get_footer(); ?>
✍️ Açıklamalar:
| Fonksiyon | Görevi |
|---|---|
the_content() | Yazının tam içeriğini gösterir |
the_tags() | Yazıya ait etiketleri listeler |
comments_template() | Yorum formu ve yorumları gösterir |
🛠️ 3. page.php – Sayfa İçeriği Şablonu
Yeni bir dosya oluştur: page.php
<?php get_header(); ?>
<main class="page-content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="page-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1><?php the_title(); ?></h1>
<div class="page-body">
<?php the_content(); ?>
</div>
</article>
<?php endwhile; endif; ?>
</main>
<?php get_footer(); ?>
Bu şablon, WordPress yönetim panelinde oluşturduğun “Hakkımızda”, “İletişim” gibi sayfalar için kullanılır.
💬 Bonus: Yorumları Açma
comments_template() fonksiyonu ile ziyaretçiler yazılara yorum yapabilir. Ancak varsayılan olarak bu bölüm boş görünebilir. Aktif etmek için:
- WP panel → Ayarlar → Tartışma → “Yorumlara izin ver” kutusunu işaretle
- Yazı düzenleme ekranında “Yorumlara izin ver” işaretli olmalı
💄 Stil Önerisi (CSS)
.single-post h1 {
font-size: 2.2rem;
margin-bottom: 10px;
}
.page-content {
max-width: 700px;
margin: 0 auto;
}
.post-thumbnail img {
max-width: 100%;
height: auto;
margin-bottom: 20px;
}
✅ Kontrol Listesi
- Yazıya tıklanınca
single.phpçalışıyor mu? - Sayfa oluşturunca
page.phpiçeriği gösteriyor mu? - Yorumlar açık mı?
- Öne çıkan görsel görünür mü?
🚀 Sonraki Yazı: functions.php ile Menü ve Widget Alanları Oluşturmak
Bir sonraki yazıda şunları yapacağız:
- Dinamik menüler oluşturacağız (
wp_nav_menu) - Yönetici panelinden kontrol edilebilir alanlar ekleyeceğiz
- Sidebar alanı ve footer widget desteği tanımlayacağız