How to add Post Thumbnails to your Theme

wailynnooJuly 3, 20103min670

ကျွန်တော်တို့ရဲ့ WordPress 3 blog မှာ post thumbnails ထည့်ဖို့အတွက် Twenty Ten Theme မှာတော့ function လေးတစ်ခုထည့်ရုံပါဘဲ။
<pre>
<?php if  ( function_exists(“has_post_thumbnail”) && has_post_thumbnail() ) { the_post_thumbnail(array(200,160), array(“class” => “alignleft post_thumbnail”)); } ?>
</pre>
အပေါ်က coding လေးကို Theme ရဲ့ content ကိုလှမ်းခေါ်တဲ့ function ရှေ့မှာ သူ့ကိုထည့်ပေးရပါမယ်။ Twenty Ten မှာအရင်ထည့်ကြည့်ကြတာပေါ့။ အရင်တုန်းက Theme တွေမှာ content ကိုခေါ်တဲ့နေရာက index.php မှာပါ။ အခု WordPress 3 ရဲ့ default theme ဖြစ်တဲ့ Twenty Ten မှာတော့ loop.php မှာ ပါ။ အဲဒီ file ရဲ့ စာကြောင်းရေ 136 မှာ အောက်က div ကိုတွေ့ပါလိမ့်မယ်။
<pre>
<div>
<?php the_content( __( ‘Continue reading <span>&rarr;</span>’, ‘twentyten’ ) ); ?>
<?php wp_link_pages( array( ‘before’ => ‘<div>’ . __( ‘Pages:’, ‘twentyten’ ), ‘after’ => ‘</div>’ ) ); ?>
</div><!– .entry-content –>
</pre>
အဲဒီမှာ content ကိုခေါ်တဲ့ function ကိုတွေ့ပါလိမ့်မယ်။ အဲဒီ function ရဲ့ ပေါ်မှာ ကျွန်တော်တို့ခုဏက code ကိုထည့်ပါမယ်။ အဲဒီတော့ ဒီလိုဖြစ်သွားပါလိမ့်မယ်။
<pre>
<div>
<?php if  ( function_exists(“has_post_thumbnail”) && has_post_thumbnail() ) { the_post_thumbnail(array(200,160), array(“class” => “alignleft post_thumbnail”)); } ?>
<?php the_content( __( ‘Continue reading <span>&rarr;</span>’, ‘twentyten’ ) ); ?>
<?php wp_link_pages( array( ‘before’ => ‘<div>’ . __( ‘Pages:’, ‘twentyten’ ), ‘after’ => ‘</div>’ ) ); ?>
</div><!– .entry-content –>
</pre>
အဲဒီ function မှာ image အရွယ်အစားကို ပြောင်းချင်ရင် (200,160) ဆိုတဲ့နေရာမှာ ကိုယ်ကြိုက်တဲ့ site ကိုထည့်နိုင်ပါတယ်။ alignleft ဆိုတဲ့နေရာမှာ လည်း aligncenter, alignright ကြိုက်တာထားနိုင်ပါတယ်။
အဲဒါပြီးရင်တော့ ကိုယ်ထည့်ချင်တဲ့ post မှာ Featured Image ထည့်ပေးလိုက်ရုံပါဘဲ။ ကျွန်တော်တို့ install လုပ်တုန်းက ပါလာတဲ့ Hello world! post လေးကို Featured Image ထည့်ကြည့်ရအောင်ပါ။ admin panel ကနေ Hello world! ကို Edit လုပ်ဖို့ဝင်လိုက်ပါ။ right side bar မှာ Set featured image ဆိုတာကိုတွေ့ပါလိမ့်မယ်။

အဲဒါကို   click ပြီး ကိုယ်ကြိုက်တဲ့ပုံ ထည့်လိုက်ပါ။ ပြီးရင်တော့ အောက်ကပုံမှာပြထားတဲ့ Use as featured image ကို နှိပ်ဖို့မမေ့ပါနဲ့။ ဒါဆိုရင်အားလုံး Ok သွားပါပြီ။

ကျွန်တော်တို့ post ကို ဒီလိုမြင်ရပါလိမ့်မယ်။

Twenty Ten မှာမဟုတ်ဘဲ အခြား Theme တစ်ခုမှာ ဆိုရင်တော့ functions.php မှာ အောက်က coding လေးကိုထည့်ပေးရပါမယ်။
<pre>
if ( function_exists(‘add_theme_support’) ) {
add_theme_support(‘post-thumbnails’);
}
</pre>
ကျန်တာကတော့ အတူတူပါဘဲ။ content ကိုခေါ်တဲ့နေရာက index.php မှာ ရှိဖို့များတယ်ဆိုတာ မမေ့ပါနဲ့။