Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

tr:Yazar Sablonlari

Since the advent of Themes in WordPress 1.5, changing the look and feel of your WordPress site has become fairly straightforward. For instance, when a viewer clicks on a link to a post author, by default he or she is taken to a page listing the posts from that particular author in chronological order, from newest posts at the top to oldest at the bottom. There are many display choices, including whether to display the complete post or post excerpts, and what additional information to display (title, category, publish date, last modified time, etc.). Each theme makes different choices, and you might want to change them.

This article explains how to change what happens when the blog viewer is visiting one of your site's author pages. This involves the use of Themes and Template files, so if you are new to template files, you might want to read Using Themes and Stepping Into Templates first.

There are many ways that you can modify the look of your author pages. Some are not really specific to author pages, such as adding text to the top of the page; you can read about such simple modifications in the Category Templates article. This article will concentrate on modifications that are specific to author template files.

Başlangıç

Yazılarda Yazar Sayfasına Bağlantı Vermek

Eğer yazar sayfalarını kullanacaksanız, muhtemelen bir yazı gösterildiğinde, yazarın sayfasına bağlantı olmasını isteyeceksiniz. Bu bağlantıyı The Loop içerisinde the_author_posts_link Tema Etiketini kullanarak oluşturabilirsiniz. Örneğin:

<p>Yazar: 
<?php the_author_posts_link(); ?></p>

Not: As of WP 2.1, the_author_link() no longer links to author pages - it links to the URL stored in that author's Profile page instead. the_author_posts_link() is currently the only way to link to a standard WP-generated author page.

Bağlantı Verilmiş Yazar Listesi

Yazar sayfalarına bağlantı vermenin diğer bir yolu ise, kenar çubuğunda (sidebarda) (veya temanızın herhangi bir yerinde) yazar listesi oluşturmaktır. wp_list_authors tema etiketi tam olarak bunu yapıyor. Yapmanız gereken tek şey aşağıdaki kodu kenar çubuğuna yerleştirmek:

<h2>Yazar Listesi:</h2>
<ul>
<?php wp_list_authors(); ?>
</ul>

Hangi Tema Dosyasını Kullanacağım?

Artık yazar sayfalarına ait bağlantılara sahip olduğumuza göre, bir sonraki adımımız yazıları göstermek için kullanacağımız tema dosyasını düzenlemek olacaktır. Buna Tema Hiyerarşisi de denir.

Hiyerarşi sistemi çok basittir. Tema Hiyerarşisi WordPress'in tema klasörünüzde kullanacağı ilk dosyayı belirler. Aşağıdaki listeye bakarsak:

  1. author.php
  2. archive.php
  3. index.php

Eğer author.php dosyanız yoksa, WordPress archive.php dosyasını arar, o da yoksa diğerini arar.

Bu yüzden, eğer yazar sayfalarınızın görünümünü değiştirmek istiyorsanız, öncelikle bir author.php dosyası oluşturmalısınız. Eğer yoksa archive.php dosyasını kopyalayarak, o da yoksa index.php dosyasını kullanabilirsiniz.. Bu makalenin devamında author.php dosyasının düzenlenmesini göreceksiniz.

Özel Yazar Bilgileri

Bu sekme yazar sayfanıza, yazarla ilgili bilgileri, örneğin isim, biyografi, ve iletişim bilgisini nasıl ekleyeceğinizi gösteriyor.

Yazar Bilgilerini Hazırlamak

Yapacağınız ilk şey yazarlara ait tema dosyasını (author.php) düzenlemek. Böylece sayfada hangi yazarın gösterileceğini anlayacak ve veritabanından bilgileri buna göre çekeceğiz.

Bunu $curauth (Current Author yani Şu an ki Yazar) denilen bir değişkenle yapabiliriz. Bunun için izlenen geleneksel yol, aşağıdaki satırları tema dosyasında The Loop öncesine yerleştirmektir:

<?php 
if(isset($_GET['author_name'])) :
    // NOTE: 2.0 bug requires: get_userdatabylogin(get_the_author_login());
    $curauth = get_userdatabylogin($author_name);
else :
    $curauth = get_userdata(intval($author));
endif;
?>

Eğer yukarıdaki çalışmıyorsa, $curauth değerini almak için başka yollar da var. Örneğin WordPress 1.2 Sürümü, WordPress 1.5 Sürümü ve daha yüksek sürümlerde çalışan bu kodu deneyin.

<?php
if(isset($_GET['author_name'])) :
    $curauth = get_userdatabylogin($_GET['author_name']);
else :
    $curauth = get_userdata($_GET['author']);
endif;
?>

Yada sadece WordPress 1.5 ve daha üst sürümlerde çalışan bu kodu deneyebilirsiniz:

<?php
if(get_query_var('author_name')) :
    $curauth = get_userdatabylogin(get_query_var('author_name'));
else :
    $curauth = get_userdata(get_query_var('author'));
endif;
?>

Eğer yukarıdakilerin hiç biri sizde çalışmıyorsa, WordPress 1.5 ve altı sürümler için bir başka seçenek daha var:

<?php
global $wp_query;
$curauth = $wp_query->get_queried_object();
?>

Yazar Bilgilerini Kullanmak

Artık $curauth değişkenine sahip olduğumuza göre, gösterilen yazarın her türlü bilgisini yayınlayabiliriz. Örneğin, yazarın takma ismini, "Ali arkadaşımızın sayfası" formatında göstermek istiyorsanız, şunu kullanmalısınız:

<p><?php echo $curauth->nickname; ?> arkadaşımızın sayfası</p>

Not: Yaptıklarımız, bir önceki bölümde elde ettiğimiz $curauth değişkeninden sonra yazılmalıdır.

Yazar takma adının yanı sıra gösterebileceğimiz bir çok bilgi daha var. Bunların hepsi WordPress kullanıcı düzenlemek ekranında çıkan bilgiler. WordPress 2.0 ve daha yüksek sürümlerde bunları kullanabilirsiniz:

  • $curauth->aim;
  • $curauth->description;
  • $curauth->display_name;
  • $curauth->first_name;
  • $curauth->ID;
  • $curauth->jabber;
  • $curauth->last_name;
  • $curauth->nickname;
  • $curauth->user_email;
  • $curauth->user_login;
  • $curauth->user_nicename;
  • $curauth->user_registered;
  • $curauth->user_url;
  • $curauth->yim;

WordPress 1.2 ve 1.5 için:

  • $curauth->user_aim;
  • $curauth->user_description;
  • $curauth->user_email;
  • $curauth->user_firstname;
  • $curauth->user_icq;
  • $curauth->user_lastname;
  • $curauth->user_level;
  • $curauth->user_login;
  • $curauth->user_msn;
  • $curauth->user_nickname;
  • $curauth->user_url;
  • $curauth->user_yim;

Bunlarda yukarıda verdiğimiz takma isim örneğiyle aynı şekilde kullanılıyor. Yazarın "Herkes tarafından görülecek ad" bilgisini ve "Biografik Bilgi" yazısını göstermek istersek eğer:

<p><?php echo $curauth->display_name; ?><br />
<?php echo $curauth->description; ?></p>

Örnek Tema Dosyası

Size örnek olması için bütün bir author.php dosyası:

<?php get_header(); ?>

<div id="content" class="narrowcolumn">

<!-- $curauth değişkeni ayarlanıyor -->

    <?php
    if(isset($_GET['author_name'])) :
        $curauth = get_userdatabylogin($author_name);
    else :
        $curauth = get_userdata(intval($author));
    endif;
    ?>

    <h2>Yazar: <?php echo $curauth->nickname; ?></h2>
    <dl>
        <dt>İnternet Sitesi</dt>
        <dd><a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a></dd>
        <dt>Hakkında</dt>
        <dd><?php echo $curauth->user_description; ?></dd>
    </dl>

    <h2><?php echo $curauth->nickname; ?> Tarafından Yazılanlar:</h2>

    <ul>
<!-- The Loop -->

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <li>
            <a href="<?php the_permalink() ?>" rel="bookmark" title="Kalıcı Bağlantı: <?php the_title(); ?>">
            <?php the_title(); ?></a>,
            <?php the_time('d M Y'); ?> in <?php the_category('&');?>
        </li>

    <?php endwhile; else: ?>
        <p><?php _e('No posts by this author.'); ?></p>

    <?php endif; ?>

<!-- End Loop -->

    </ul>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

İleri Seviye Bilgiler

Çeviri Notları

  • Üst paragrafı türkçeleştiremedim, kusura bakmayın...
  • Nickname yerine takma isim, Link yerine bağlantı kelimelerini tercih ettim.
  • Çeviri: * Semih Aksu