Temel WordPress Kodları

Kod Günlüğümden merhabalar, WordPress için tema oluştururken yada html to wordpress (entegre) yaparken mutlaka lazım olacak wordpress kodlarını bir araya topladım
Header Çağırma Gösterme, Menü Oluşturma, Footer Çağırma Gösterme, WordPress Sayfa Karakter Kodlaması Tanımlaması, Blog Adı / Site Adı Gösterme vs. daha fazlasını aşağıda topladım yararlı olması dileği ile

// Header Çağırma:
<?php get_header(); ?>
 
// Footer Çağırma:
<?php get_footer(); ?>
 
// Karakter Kodlaması
<?php bloginfo( 'charset' ); ?>
 
//Blog Adı
<?php bloginfo('name'); ?>
 
//Blog Adresi:
<?php bloginfo('url'); ?>
 
//Title
<?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?>
 
//Tema Yolu
<?php bloginfo('template_url'); ?>
 
//Stil Dosyası
<?php bloginfo('stylesheet_url'); ?>
 
 
//Menü Oluşturma Functions.php
 
// Görünüm -> Menüler alanının görünmesi için
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 
 
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 wp_head(); ?>
 
// footer.php içinde bulunması gereken, functions.php içinde tanımlı javascript dosyalarının eklenmesini sağlayan fonksiyon
 
<?php wp_footer(); ?>
 
// functions.php içine css tanımlaması yapmak için
 
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
 
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österm için;
 
<?php bloginfo('template_directory'); ?>
 
// header.php title gösterimi
 
<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
 
 
// header.php meta tag description tanımlaması ve gösterimi
 
<meta name="description" content="<?php bloginfo("description"); ?>">
 
// archive.php yada category.php 'de kategori açıklaması gösterimi
 
<?php the_archive_description(); ?>
 
// archive.php yada category.php 'de kategori adı gösterimi
 
<?php the_archive_title(); ?>
 
 
// archive.php , page.php yada single  içinde tarih zaman gösterimleri:
<?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 if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 
//While Döngüsü Bitiş
<?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
 
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 the_category(', '); ?>
 
//Yazı Başlığı
<?php the_title(); ?>
 
//Yazı Adresi / link
<?php the_permalink(); ?>
 
// yazar adı
<?php the_author();  ?>
 
// yorum sayısı gösterir
<?php comments_number('0 Yorum','1 Yorum','% Yorum'); ?>
 
//Yazı yada sayfa içinde Thumbnail Gösterme
 
<?php the_post_thumbnail_url(); ?>
 
//Thumbnail Funtions (functions.php yazılacak)
add_theme_support( 'post-thumbnails' );
add_image_size( 'anasayfa', 155, 265, true );
 
// yazı kısaltma (kısa yazı gösterir)
<?php the_excerpt(); ?>
 
 
//The Exceprt Functions (functions.php yazılacak) (bu fonksiyonu tanımlayarak gösterilecek karakter sayısı belirtebilirsiniz)
function new_excerpt_length($length) {
return 12;
}
add_filter('excerpt_length', 'new_excerpt_length');
 
//Yazı Tarihi
<?php the_time('d F Y'); ?>
 
// bir başka yazı kısaltma limitleme fonksiyonu (daha kullanışlı)
function icerik_kisalt($char) { 
         $content = get_the_content($post->ID); 
         $content = substr($content,0,$char); 
         echo $content; 
}  
 
//index.php de kullanımı: 
<?php icerik_kisalt(25);?>
 
// SAYFALAMA - PageNavi Functions (functions.php yazılacak)
 
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)."'>&laquo;</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)."'>&raquo;</a>";
echo "</div>\n";
}
}
 
//Sayfalama Çağırma
<?php sayfalama(); ?>
 
 
// Görünüm -> Bileşenler bölümünü aktif etmek için functions.php
 
/* 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 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
 
/**
 * 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.
     *
     * @return 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' );
 
function register_foo() { 
    register_widget( 'Foo_Widget' ); 
}
?>
// single.php de yorumları göstermek
<?php comments_template(); ?>
 
//Sidebar.php Çağırma Kodu:
<?php get_sidebar(); ?>
Bu İçeriğe Puan Verebilirsiniz
[Toplam: 3 Ortalama: 4.3]

“Temel WordPress Kodları” üzerine 2 yorum

Bir cevap yazın

E-posta hesabınız yayımlanmayacak.

This site uses Akismet to reduce spam. Learn how your comment data is processed.