WordPress Temel Tema Kodları (Tema Yapımında Kullanılan Kodlar)

Merhaba arkadaşlar, wordpress ile tema yapımında kullanılan temel kodları sizinle paylaşmak istedim. Umarım yararınıza olacaktır.

1-

Kod:
<?php bloginfo('template_url'); ?>

Tema Url Kodu

2-

Kod:
<?php bloginfo('siteurl');?>

Site Url Kodu

3-

Kod:
<?php get_header(); ?>

Header.php Sayfa çağırma kodu

4-

Kod:
 <?php get_sidebar(); ?>

Sidebar.php Sayfa çağırma kodu

5-

Kod:
<?php get_footer(); ?>

Footer.php Sayfa çağırma kodu

6-

Kod:
<?php include (TEMPLATEPATH . '/sidebar2.php'); ?>

Herhangi bir sayfayı çağırma kodu

7-

Kod:
<?php query_posts('showposts=8&cat=1');?>
   <?php while (have_posts()) : the_post(); ?>

   Çağıralacak kod				

   <?php endwhile; ?>

Belirlediğimiz sayıda içerik Listeleme Kodu. Not: Bu kod ile sayfalama çalışmaz.

8-

Kod:
<?php the_permalink() ?>

İçerik linki kodu

9-

Kod:
<?php the_title(); ?>

içerik başlığı kodu

10-

Kod:
<?php if(function_exists('the_views')) { the_views(); } ?>

Wp-post views eklentisi izleme sayısı kodu

11-

Kod:
<?php the_category(', '); ?>

İçerik kategori adı gösterme kodu

12-

Kod:
<?php the_tags(' ', ', ', ''); ?>

Etiket Kodu

13

Kod:
<?php if( get_post_meta($post->ID, "resim", true) ): ?>
    <?php echo get_post_meta($post->ID, "resim", true); ?>
    <?php else: ?>
    <?php endif; ?>

Özel alan gösterim kodu

14-

Kod:
<?php the_content_rss('', TRUE, '', 10); ?>

Belli kelimede içerik yazısı gösterme kodu

15-

Kod:
<?php
	$my_query = new WP_Query('orderby=rand&showposts=15');
	while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;
?>

Çağırılacak kod

<?php endwhile; ?>

Belirlediğimiz sayıda içerikleri listeleme kodu Not: Sayfalama çalışır kullanabilirsiniz.

16-

Kod:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

Çağırılacak kod

<?php endwhile; ?>  
<div class='sayfalama'><?php wp_pagenavi() ?></div>
<?php else : ?>
<div><?php next_posts_link(__('&laquo; Older Entries')) ?></div>
<div><?php previous_posts_link(__('Newer Entries &raquo;')) ?></div>
<div></div>
 <?php endif; ?>

Sayfalama eklentisi wp-pagenavi dahil, içerik sayısının admin paneli okuma kısmında ayarlandığı içerik listeleme kodu

17 –

Kod:
<?php 
			if (have_posts()) : while (have_posts()) : the_post(); 
			$do_not_duplicate = $post->ID;
			?>
			içerik kodu <?php the_content(''); ?>
			<?php endwhile; else : endif; ?>

single.php ve page.php içine içerik yani eklediðimiz yazının tamamını gösterme kodu

18-

Kod:
<?php the_content(''); ?>

single.php içerik yazısının kodu 17. kodda mevcut.

19-

Kod:
<?php comments_template(); ?>

Yorum için comments.php çağırma kodu

20-

Kod:
<li <?php if(is_home()) { echo ' '; } ?>><a href="<?php bloginfo('url'); ?>">Anasayfa</a></li>
<?php wp_list_categories('depth=3&child_of=1&hide_empty=0&orderby=name&show_count=0&use_desc_for_title=1&title_li='); ?>

Kategorileri veya alt kategorileri listeleme kodu.

21-

Kod:
<?php
  global $wpdb;
  $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10";

  $comments = $wpdb->get_results($sql);
  $output = $pre_HTML;
  $output .= "\n<ul>";
  foreach ($comments as $comment) {
    $output .= "\n<li>".strip_tags($comment->comment_author) .":" . "<a href=\"" . get_permalink($comment->ID)."#comment-" . $comment->comment_ID . "\" title=\"on ".$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a></li>";
  }
  $output .= "\n</ul>";
  $output .= $post_HTML;
  echo $output;
?>

Yorumları gösterme kodu

22-

Kod:
<?php
    $wp_query = new WP_Query();
    $wp_query->query('showposts=5&cat=-416&paged='.$paged);
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
	içerik gelicek
	<?php endwhile; ?>

İstemediğimiz kategoriyi kategoriyi göstrmemek için kullandığımız içerik listeleme kodu .(cat=-416 dikkat ediniz, Bu kategori yazıları gözükmeyecek)

23-

Kod:
<?php wp_link_pages('before=<p>&after=</p>&pagelink=%.Bölüm'); ?>

Part sistemi için içerik içinde bölümlere ayırma kodu nextpage kodunu içeriğe yazarak

24-

Kod:
<?php the_time('l, F jS, Y') ?>

Tarih gösterme kodu

25-

Kod:
<?php the_author(', '); ?>

Yazar İsmi kodu

26-

Kod:
<?php the_category(', '); ?>

Kategori adı kodu

27-

Kod:
<?php previous_post_link('%link') ?> Önceki Link
    <?php next_post_link('%link') ?> Sonraki link

İlgili içerik yerleştirildiğinde o içerikten önceki ve sonraki konuların linkini verir.

28-

Kod:
<?php
$args=array(
  ‘orderby’ => ‘name’,
  ‘order’ => ‘ASC’
  );
$categories=get_categories($args);
$cat_count = 0;
foreach($categories as $c) {
$cat_count++;
}
$count_posts = wp_count_posts();
$published = $count_posts->publish;
?>

Toplam içerik sayısı :<?php echo $published;?>

29-

Kod:
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>

Pagenavi eklentisi sayfalama kodu

30-

Kod:
<title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' :'; } ?> <?php bloginfo('name'); ?></title>

header.php için title baslık kodu

31-

Kod:
<?php comments_number('0 Yorum','1 Yorum','% Yorum'); ?>

İlgili içeriğin yorum sayısı kodu