Languages: English • Français • Tags 日本語 Türkçe • (Add your language)
Koşul Etiketleri farklı durumlarda hangi içeriğin gösterileceğine karar verirken kullanılırlar. Örneğin, belli yazılarınızı sadece ana sayfanızda göstermek isteyebilirsiniz. Bu durumda is_home() Koşul Etiketi ile bu işi kolaylıkla yapabilirsiniz.
Not: Bu etiketler WordPress'teki Tema Hiyerarşisi'ne bağlıdır.
Bütün koşul etiketleri bir durumun oluşup, oluşmadığını kontrol eder ve TRUE ya da FALSE değeri döndürür. Aşağıdaki açıklamalarda bu etiketlerin TRUE değeri döndürdüğü durumlar anlatılmıştır, tersi durumda FALSE değeri döndüreceklerdir. Bu etiketler ayrıca parametre de alabilmektedirler.
Not: Eğer sitenizde Ana sayfa olarak statik bir sayfa kullanıyorsanız bu etiket yazılarınızı gösterdiğiniz sayfada TRUE değeri alacaktır.
Bu bölüm Sayfalar ile ilgilidir, sitenizde üretilen diğer yazılar için değildir.
Henüz is_subpage() fonksiyonu tanımlanmış değil ancak aşağıdaki küçük kod ile bu testi yapabilirsiniz:
<?php
// Kodu bir fonksiyon içerisinde kullanıyorsanız
//$post değişkenini global olarak alınız.
global $post;
if ( is_page() && $post->post_parent ) {
// Bu bir alt sayfa
} else {
// Alt sayfa değil
}
?>
Bu fonksiyonu temanızın Tema fonksiyonları (functions.php) dosyasına ekleyebilirsiniz:
Bu bölüm Türkçeleştirilecek
function is_tree($pid) { // $pid = The page we're looking for pages underneath
global $post; // We load this as we're outside of the post
if(is_page()&&($post->post_parent==$pid||is_page($pid))) return true; // Yes, it's in the tree
else return false; // No, it's outside
};
and call is_tree('id') to see if the page is in the tree. In the example below is_tree('2') would replace "is_page('about') || $post->post_parent == '2'" inside the first if tag. Note that if you have more than one level of pages the parent page is the one directly above and not the one at the top of the tree.
If you need to test whether this is a particular page OR a child of that page (e.g. to present a different banner on different sections of a page-based site), get the parent page IDs from the back-end, then use code like this:
<?php
if ( is_page('about') || $post->post_parent == '2' ) {
$bannerimg = 'home.jpg';
} elseif ( is_page('learning') || $post->post_parent == '56' ) {
$bannerimg = 'teaching.jpg';
} elseif ( is_page('admissions') || $post->post_parent == '15' ) {
$bannerimg = 'admissions.jpg';
} else {
$bannerimg = 'home.jpg'; // Fall-through
}
?>
If you wish to test this numerous times it is advisable to create a function (is_cpage()) which can easily be maintained. For example, if is_subpage() is introduced in to wp, you can change your function in functions.php without having to change multiple uses.
Version 2.5 sürümü ile birlikte sayfanın bir şablon kullanıp, kullanılmadığını kontrol etmeye izin verilmiştir.
Note: Fonksiyonları yazarken "is" ve "in" arasında büyük fark olduğunu unutmayın.
Ayrıca bkz. is_archive() and Category Templates.
Ayrıca bkz. is_archive() ve Tag Templates.
Ayrıca bkz. is_archive() and Author Templates.
Ayrıca bkz. is_archive().
<?php
// Bir fonksiyonun içerisinde ise $post değişkenini al
global $post;
if ( empty($post->post_excerpt) ) {
// Bu yazının özeti yok
} else {
// Bu yazının özeti var
}
?>
Aşağıdaki örnekler koşul etiketlerinin nasıl kullanılabileceğini göstermektedir.
Bu örnek tekil bir sayfa gösterildiğinde özel bir mesaj iletmek için is_single() etiketinin kullanımını gösterir:
if (is_single())
{
echo 'Bu ' . single_cat_title() . ' kategorisindeki güzel yazılardan birisi!';
}
Eğer birisi sitemize tarihe dayalı olarak girmişse, farklı yıllardaki yazıları, farklı renklerle gösterelim:
<?php
// The Loop döngüsü başlıyor
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<small><?php the_time('d F Y') ?> <!-- by <?php the_author() ?> --></small>
<?php
// tarih temelli arşiv mi gösteriyoruz?
if (is_date())
{
if (date('Y') != get_the_date('Y'))
{
// bu tarih önceki bir yılda yazılmış
// bu yüzden bu içeriği "oldentry" CSS sınıfnda gösterelim
echo '<div class="oldentry">';
} else {
echo '<div class="entry">';
}
} else {
echo '<div class="entry">';
}
the_content('Devamı »');
?>
</div>
Bu örnek okuyucu farklı sayfaları incelerken yan menüde farklı içerik göstermeyi anlatır:
<!-- begin sidebar -->
<div id="sidebar">
<?php
// Görüntülenen sayfayla ilgili olarak kategorileri listeleyelim.
if (is_home()) {
// Ana sayfadayız, ana kategorileri listeleyelim
echo "<ul>";
wp_list_categories('optionall=0&sort_column=name&list=1&children=0');
echo "</ul>";
} elseif (is_category()) {
// Bir kategori içeriğini görüntülüyoruz, bu yüzden bütün kategorileri gösterelim
echo "<ul>";
wp_list_categories('optionall=1&sort_column=name&list=1&children=1&hierarchical=1');
echo "</ul>";
} elseif (is_single()) {
// Tekil bir yazı görüntülüyoruz, bu yüzden yan menüde herhangi bir şey görüntüleyelim
} elseif (is_page()) {
// Statik bir sayfa görüntülüyoruz, ama hangisi?
if (is_page('About')) {
// Hakkında sayfamızour about page.
echo "<p>Bu hakkımda sayfam!</p>";
} elseif (is_page('Portfolio')) {
echo "<p>Bu Portfolio sayfam!</p>";
} else {
// Diğer bütün sayfalar
echo "<p>Pedro için oy verin!</p>";
}
} else {
// Diğer herşey (arşivler, aramalar, 404 hata sayfaları, vs.)
echo "<p>Merhaba siteme hoş geldiniz!</p>";
} // Hepsi bu!
?>
<form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div>
<input type="text" name="s" id="s" size="15" />
<input type="submit" value="<?php _e('Search'); ?>" />
</div>
</form>
</div>
<!-- end sidebar -->
The Creating an Error 404 Page article has an example of using the PHP conditional function
isset()
in the Writing Friendly Messages section.
The Dynamic Menu Highlighting article discusses how to use the conditional tags to enable highlighting of the current page in a menu.
is_home(), is_front_page(), is_search(), is_404(), is_singular(), is_page(), is_attachment(), is_local_attachment(), is_single(), is_sticky(), is_archive(), is_category(), is_tag(), is_author(), is_date(), is_year(), is_month(), is_day(), is_time(), is_admin(), is_preview(), is_paged(), is_page_template(), is_plugin_page(), is_new_day(), is_feed(), is_trackback(), is_comments_popup(), comments_open(), pings_open(), is_taxonomy(), is_taxonomy_hierarchical()