Türkiye'nin
[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]alanında hizmet veren en kaliteli paylaşım platformu olan
I R C r e h b e r i forum sitemizde sizler için geniş kapsamlı ,
wordpress tema yapımında veya
html temaları wp temaya ( html to wordpress themes ) çevirmenizde çok işinize yarayacak temel kodlarını sıralamaya çalışalım.
WordPress Teması Nedir ?
Altta çalışmakta olan
WordPress yazılımını kullanarak web sitesinin görünümünü ve işlevini belirliyor. Temayı bir anlamda kıyafet olarak düşünmek mümkün. Seçilen temaya göre web sitesi;
ciddi, enerjik, resmi, çocuksu, rahat ya da eğlenceli görünebiliyor.
// Header Çağırma
PHP- Kodu
<?php get_header(); ?>
// Footer Çağırma
PHP- Kodu
<?php get_footer(); ?>
// Karakter Kodlaması
PHP- Kodu
<?php bloginfo( 'charset' ); ?>
//Blog Adı
PHP- Kodu
<?php bloginfo('name'); ?>
//Blog Adresi
PHP- Kodu
<?php bloginfo('url'); ?>
//Title
PHP- Kodu
<?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?>
//Tema Yolu
PHP- Kodu
<?php bloginfo('template_url'); ?>
//Stil Dosyası
PHP- Kodu
<?php bloginfo('stylesheet_url'); ?>
//Menü Oluşturma Functions.php
// Görünüm -> Menüler alanının görünmesi için
PHP- Kodu
add_theme_support('menus');
register_nav_menus (
array(
'ust-menu' => __('Üst Menü','theme')
)
);
// header yada
footer gibi alanlarda görünecek kısım
PHP- Kodu
<?php
wp_nav_menu (
array(
'theme_location' => 'ust-menu',
'container' => 'ul',
'menu_id' => 'main-menu',
'menu_class' => 'main-menu font-mountainsre'
)
);
/*
** container: menünüzün en dışındaki etiketi ifade ediyor,
** menu_id : containerda belirtilen etiketin id'sini belirtiyor
** menu_class : containerda belirtilen etiketin classını belirtiyor.
*/
?>
// header.php içinde bulunması gereken,
functions.php içinde tanımlı
css dosyalarının eklenmesini sağlayan fonksiyon
PHP- Kodu
<?php wp_head(); ?>
// footer.php içinde bulunması gereken,
functions.php içinde tanımlı
javascript dosyalarının eklenmesini sağlayan fonksiyon
PHP- Kodu
<?php wp_footer(); ?>
// functions.php içine
css tanımlaması yapmak için
PHP- Kodu
function cssekle() {
wp_register_style('manuelcss', get_template_directory_uri().'/manuel.css',array(), 1, 'all' );
wp_enqueue_style('manuelcss');
}
add_action('wp_enqueue_scripts','cssekle);
// functions.php içine
javascript tanımlaması yapmak için
PHP- Kodu
function jsekle() {
wp_register_script('scripts', get_template_directory_uri().'/scripts.js', array(), 1, 1);
wp_enqueue_script('scripts');
}
add_action('wp_enqueue_scripts','jsekle');
// front-page.php yada diğer iç sayfalarda tema yolunu belirtmek gösterim için;
PHP- Kodu
<?php bloginfo('template_directory'); ?>
// header.php title gösterimi
PHP- Kodu
<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
// header.php meta tag description tanımlaması ve gösterimi
PHP- Kodu
<meta name="description" content="<?php bloginfo("description"); ?>">
// archive.php yada
category.php 'de kategori açıklaması gösterimi
PHP- Kodu
<?php the_archive_description(); ?>
// archive.php yada
category.php 'de kategori adı gösterimi
PHP- Kodu
<?php the_archive_title(); ?>
// archive.php , page.php yada
single içinde tarih zaman gösterimleri
PHP- Kodu
<?php echo get_the_date('d'); ?> // gün gösterir
<?php echo get_the_date('m'); ?> // ay gösterir
<?php echo get_the_date('y'); ?> // yıl son iki hane gösterir
<?php echo get_the_date('d.m.Y'); ?> // tarih tamamını gösterir
//While Döngüsü Başlangıç
PHP- Kodu
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
//While Döngüsü Bitiş
PHP- Kodu
<?php endwhile; else: ?>
<?php _e('Sonuç Bulunamadı.'); ?>
<?php endif; ?>
// The loop / döngü baştan sona
// single.php içinde kullanılırsa tek yazı,
archive.php,
category.php gibi sayfalarda kullanılırsa ilgili kategori yada etikete ait tüm yazıları listeler yazının tamamını gösterilmemesi için kısaltma fonksiyonu
the_excerpt(); kullanılması gerekir
PHP- Kodu
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_content(); // bu alan yazı içeriğinin gösterileceği alandır
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
//Yazı Kategorisi
PHP- Kodu
<?php the_category(', '); ?>
//Yazı Başlığı
PHP- Kodu
<?php the_title(); ?>
//Yazı Adresi / link
PHP- Kodu
<?php the_permalink(); ?>
// Yazar adı
PHP- Kodu
<?php the_author(); ?>
// Yorum sayısı gösterir
PHP- Kodu
<?php comments_number('0 Yorum','1 Yorum','% Yorum'); ?>
//Yazı yada sayfa içinde
Thumbnail Gösterme ( Küçük Resim )
PHP- Kodu
<?php the_post_thumbnail_url(); ?>
//Thumbnail Funtions (
functions.php yazılacak)
PHP- Kodu
add_theme_support( 'post-thumbnails' );
add_image_size( 'anasayfa', 155, 265, true );
// Yazı kısaltma (kısa yazı gösterir)
PHP- Kodu
<?php the_excerpt(); ?>
//The Exceprt Functions (
functions.php yazılacak) (bu fonksiyonu tanımlayarak gösterilecek karakter sayısı belirtebilirsiniz)
PHP- Kodu
function new_excerpt_length($length) {
return 12;
}
add_filter('excerpt_length', 'new_excerpt_length');
//Yazı Tarihi
PHP- Kodu
<?php the_time('d F Y'); ?>
// Bir başka yazı kısaltma limitleme fonksiyonu (daha kullanışlı)
PHP- Kodu
function icerik_kisalt($char) {
$content = get_the_content($post->ID);
$content = substr($content,0,$char);
echo $content;
}
//index.php de kullanımı
PHP- Kodu
<?php icerik_kisalt(25);?>
// SAYFALAMA -
PageNavi Functions (
functions.php yazılacak)
PHP- Kodu
function sayfalama($pages = '', $range = 3)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class='wp-pagenavi'>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>«</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>»</a>";
echo "</div>\n";
}
}
//Sayfalama Çağırma
PHP- Kodu
<?php sayfalama(); ?>
// Görünüm -> Bileşenler bölümünü aktif etmek için
functions.php
PHP- Kodu
/* sidebar tanımlama
*/
if ( function_exists('register_sidebar') ) {
$sidebar1 = array(
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
'name'=>__( 'My sidebar 1', 'textdomain' ),
);
register_sidebar($sidebar1);
}
// Bileşenleri
archive.php category.php single.php yada herhangi bir yerde göstermek için yukardaki tanımlamayı yaptıktan sonra
PHP- Kodu
<?php dynamic_sidebar( 'My sidebar 1' ); ?>
şeklinde kullanabilirsiniz.
// widget oluşturmak ve
bileşenler bölümünde göstermek için (
functions.php eklenecek kodlar)
PHP- Kodu
<?php
/**
* Adds Foo_Widget widget.
*/
class Foo_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
'foo_widget', // Base ID
'Foo_Widget', // Name
array( 'description' => __( 'A Foo Widget', 'text_domain' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
echo $before_widget;
if ( ! empty( $title ) ) {
echo $before_title . $title . $after_title;
}
echo __( 'Hello, World!', 'text_domain' );
echo $after_widget;
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'text_domain' );
}
?>
<p>
<label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* [MENTION=253]Return[/MENTION] array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // class Foo_Widget
?>
<?php
// Register Foo_Widget widget add_action(
'widgets_init', 'register_foo' );
PHP- Kodu
function register_foo() {
register_widget( 'Foo_Widget' );
}
?>
//
single.php de yorumları göstermek
PHP- Kodu
<?php comments_template(); ?>
//Sidebar.php Çağırma Kodu
PHP- Kodu
<?php get_sidebar(); ?>