☙ 1 dk okuma süresi
☙ 28 Ağu 2019 ☙ 10.731
☙ 28 Ağu 2019 ☙ 10.731
Herkese Merhaba,
WP Kod Deposu, oluşturduğumuz html temayı wordpress'e eklerken kodlar üzerinde bazı değişiklikler yapmamız gerekiyor. Aşağıdaki kodlar; her wordpress tasarımının entegre işleminde gerekecek en temel kodlardır.
INDEX.PHP
- Header Çağırma:
<?php get_header(); ?> - Footer Çağırma:
<?php get_footer(); ?> - Sidebar Çağırma:
<?php get_sidebar(); ?> - Özel Sidebar:
<?php if ( is_active_sidebar( 'left-sidebar' ) ) : ?> <ul id="sidebar"> <?php dynamic_sidebar( 'left-sidebar' ); ?> </ul> <?php endif; ?> - WP Tema içinden dosya çağırma:
<?php get_template_part('extra/sidebar-right'); ?> - PHP Tema içinden dosya çağırma:
<?php include( 'çağrılacak-dosya.php' ); ?>
STYLE.CSS
- Temanızın Bilgilerini Tanımlama:
/* Theme Name: Tema Adı (Örnek Tema) Theme URI: Tema Linki Author: Tema Sahibi Author URI: Tema Sahibi URL Description: Tema Açıklama Version: Tema Versiyonu Text Domain: ornektema Tags: blog, portfolio, grid-layout, one-column, accessibility-ready */
HEADER.PHP
- Meta Charset: Türkçe karakter olayı vs.
<meta charset="<?php bloginfo( 'charset' ); ?>"> - Title:
<?php wp_title( '|', true, 'right' ); ?> - Sitenizin Linki (Anasayfa):
<?php bloginfo('url'); ?> - Sitenizin Adı:
<?php bloginfo('name'); ?> - Sitenizin Açıklaması:
<?php bloginfo('description'); ?> - Tema Ana Konumu:
<?php bloginfo('template_directory'); ?> - Doğrudan Style.css Çağırma:
<?php bloginfo('stylesheet_url'); ?> - WP Arama Kutusu:
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>"> <input type="text" name="s" id="s" /> <input type="button" value="" /> </form> - WordPress Eklentileri Çalışabilmesi İçin *:
<?php wp_head(); ?> </head> - WordPress Eklentileri Çalışabilmesi İçin *:
<?php wp_footer(); ?> </body> - Body Class:
<body <?php body_class(); ?>>
YAZI DÖNGÜSÜ (Loop)
- Klasik Loop:
<?php get_header(); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; get_sidebar(); get_footer(); ?> - Kategoriye Göre Loop:
<?php query_posts('showposts=6&orderby=date&cat=6'); if (have_posts()) : while (have_posts()) : the_post(); ?> <a href="<?php the_permalink() ?>"> <?php the_title(); ?> </a> <?php endwhile;else : endif; ?> - Sayfada İki veya Daha Fazla Loop Olacaksa "the_query" etiketinin adı değiştirilerek bu kod kullanılabilir;:
<?php $the_query = new WP_Query('showposts=6&orderby=date&cat=145'); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php the_title(''); ?> <?php the_excerpt(''); ?> <?php endwhile; ?> <!-- end of the loop --> <?php wp_reset_postdata(); ?> <?php else : ?> <p><?php esc_html_e( 'Hiç yazı yok.' ); ?></p> <?php endif; ?> - Farklı kategoriye ait posta farklı muamele:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php if (has_category('fikir',$post->ID)) : ?> <div class="post-fikir"> ...</div> <?php else: ?> <div class="post"> ...</div> <?php endif; ?> <?php endwhile;else: ?> <?php endif; ?>
SINGLE.PHP
- Yazı ID:
<?php the_ID(); ?> - Yazı İçeriği Full:
<?php the_content(); ?> - Yazı İçeriği Özet:
<?php the_excerpt(); ?> - Yazı Başlığı:
<?php the_title(); ?> - Yazı Linki:
<?php the_permalink(); ?> - Yazı Kategorisi:
<?php the_category(', '); ?> - Yazı Okunma Sayısı (WpPostViews eklentisi gerekli):
<?php if(function_exists('the_views')) { the_views(); } ?> - Yazının Yazarı:
<?php the_author(); ?> - Yazarın Avatarı (loop içinde):
<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?> - Yazarın Avatarı (loop dışında):
<?php global $current_user; get_currentuserinfo(); echo get_avatar( $current_user->ID, 64 ); ?> - Yazı Öne Çıkan Görsel URL'si (standart):
<?php the_post_thumbnail_url( 'full' ); ?> <?php the_post_thumbnail( 'full', array( 'class' => 'img-responsive' ) ); ?> - Öne Çıkan Görsel Varsa Şu Boyutlarda Gelsin (ozel-thumbnail) ve Lightbox içinde (custom-thumbnail) tanımlı büyük boyutta gözüksün, Yoksa Varsayılan Resim Gözüksün:
<?php if ( has_post_thumbnail() ) { $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'custom-thumbnail'); echo '<a href="'.esc_url($featured_img_url).'" rel="lightbox">'; the_post_thumbnail('ozel-thumbnail'); echo '</a>'; } else { ?> <img src="<?php bloginfo('template_directory'); ?>/images/pic07.jpg" alt="<?php the_title(); ?>" /> <?php } ?> - Yorumlar:
<?php comments_template(); ?> - Etiketler:
<?php the_tags( 'Etiketler: ', ' • ', '<br />' ); ?> - Tüm Etiketler Bulutu:
<?php wp_tag_cloud(array( 'smallest' => 10, //az kullanılan etiketin boyutu 'largest' => 18, //sık kullanılan etiketin boyutu 'unit' => 'px', //boyutlandırma birimi 'orderby' => 'name', //sıralama ölçünü "isim" (alfebetik) 'order' => 'ASC', //Sıralama (A ile başlar) 'exclude' => 6 //Liste dışı kalacak olan etiket idsi (opsiyonel) )); ?> - Yalnızca yazarın görebileceği 'Yazıyı Düzenle' linki:
<?php edit_post_link('Yazıyı Düzenle'); ?>
FUNCTIONS.PHP
- Temel Kodlar:
<?php add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) ); add_theme_support( 'automatic-feed-links' ); add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) ); add_theme_support( 'post-thumbnails' ); add_image_size( 'edit-thumb', 400, 220, true ); function ozel_excerpt_length( $length ) { return 22; } add_filter( 'excerpt_length', 'ozel_excerpt_length', 999 ); ?> - Sidebar Alanı Eklemek:
<?php /** * Add a sidebar. */ function hkk_sidebar_add() { register_sidebar( array( 'name' => __( 'Sol Kenar' ), 'id' => 'sol-kenar', 'description' => __( 'Bu yan kenarı her sayfada solda görebiliriz.' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<header class="widgettitle major"><h2>', 'after_title' => '</h2></header>', ) ); } add_action( 'widgets_init', 'hkk_sidebar_add' ); ?> - Menu Alanı Eklemek:
<?php add_action( 'after_setup_theme', 'register_custom_nav_menus' ); function register_custom_nav_menus() { register_nav_menus( array( 'pluginbuddy_mobile' => 'PluginBuddy Mobile Navigation Menu', 'footer_menu' => 'My Custom Footer Menu', ) ); } ?> - Anasayfa Loop'ta bazı kategorilerin çıkmasını engellemek:
<?php function excludeCat($query) { if ( $query->is_home ) { $query->set('cat', '-193,-194,-217'); } return $query; } add_filter('pre_get_posts', 'excludeCat'); ?> - Kategoriye göre farklı single göstermek:
- Misal; Müzik kategorisinde olan yazı ile normal bi kategoriye ait yazının gösterimleri farklı olsun. Müzik yazısında player çıksın vesaire..
Kullanımı: ardından single-category-yer-imleri.php adında dosya oluşturup içerisini düzenliyoruz.<?php add_filter('single_template', 'check_for_category_single_template'); function check_for_category_single_template( $t ) { foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-category-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-category-{$cat->slug}.php"; if($cat->parent) { $cat = get_the_category_by_ID( $cat->parent ); if ( file_exists(TEMPLATEPATH . "/single-category-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-category-{$cat->slug}.php"; } } return $t; } ?>
PAGE.PHP
- Özel Sayfa Oluşturma:
<?php get_header(); /* * Template Name: Display Authors */ ?>
BONUS
- Şuan ki sayfa şu ise:
<?php if ( is_front_page() && is_home() ) { // Default homepage } elseif ( is_front_page() ) { // static homepage } elseif ( is_home() ) { // blog page } else { //everything else } ?> - Üye Giriş Yapmışsa:
<?php if ( is_user_logged_in() ) { ?> <a href="<?php echo wp_logout_url(); ?>">Çıkış</a> <?php } else { ?> <a href="/wp-login.php" title="Giriş Yap" rel="home">Giriş</a> <?php } ?> - JQMIGRATE: Migrate is installed, version 1.4.0 HATASI:
<?php add_action( 'wp_default_scripts', function( $scripts ) { if ( ! empty( $scripts->registered['jquery'] ) ) { $scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) ); } } ); ?> - HATASI: Sayfada boşluklar görünmesi:
a. klasik notepad.exe ile düzelt a. klasik notepad.exe ile düzelt b. ya da notepad++ da UTF-8 without BOM c. Notepad++ yeni sürümlerinde gelen güncelleme ile artık UTF-8 Olarak Kodla'yı kullanıyoruz. WordPress <code> ya da <pre> Tagındaki Tırnak İşaretlerinin Otomatik Değişmesi a. WP'nin dediğine göre bu olayı karakterlerin html kodunu kullanarak çözebilirmişiz. Bu da şöyle ki " yerine " yazacağız, ' yerine ise ' yazacağız. Tabii bunlar HTML kod kısmında. Kaynak: codex | diğer html karakter kodları b. başka bi kaynakta bi abimiz olaya tertemiz çözüm getirmiş. Artık çalışmıyor. Kaynak: Fayazmiraz c. Güncel Çözüm functions.php: remove_filter('the_content', 'wptexturize');
wordpress kod arşivi, wp code archive, code bank..
[…] WP KOD DEPOSU'nu görmüşseniz, tema yapımında kullandığım en temel kodlar orada yer alıyor. Oradaki […]