Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

How to make WordPress theme – part 3

wailynnooJune 25, 20107min2060

ဒီနေရာမှာ ကျွန်တော်တို့ theme ကိုပိုမိုပြည့်စုံအောင် comments.php ဆိုတဲ့ file ကိုဆက်ရေးကြတာပေါ့။ ကျွန်တော်တို့ အရင်ရေးထားတဲ့ အထဲမှာ comments.php file မပါပါဘူး။ ဒါပင်မယ့် comments လည်းပေးလို့ရသလို ပြလည်းပြပေးနိုင်ပါတယ်။ ဒါကဘာကြောင့်လည်းဆိုရင် ကျွန်တော်တို့ theme မှာ comments.php file မပါရင် \wp-content\themes\default အောက်က comments.php ကိုယူသုံးပါလို့ WordPress ကရေးထားလို့ပါ။
အခုကိုယ့် comments file ကိုကိုယ့်ဟာကိုယ်စရေးကြတာပေါ့။
ကျွန်တော်ကတော့ ဒီ file ကိုသုံးပိုင်းပိုင်းထားပါတယ်။

အပိုင်း(၁)

<?php
if (!empty($_SERVER[‘SCRIPT_FILENAME’]) && ‘comments.php’ == basename($_SERVER[‘SCRIPT_FILENAME’]))
die (‘Please do not load this page directly. Thanks!’);

ဒီ coding လေးကတော့ ကျွန်တော်တို့ရဲ့ comments ဖိုင်ကို တိုက်ရိုက်ကြည့်လို့မရအောင် တားဆီးထားတာပါ။ post နဲ့မှတွဲကြည့်လို့ ရအောင်လုပ်ထားတာပါ။ ‘Please do not load this page directly. Thanks!’ ဆိုတဲ့စာသားနေရာမှာ သင်ကြိုက်တာ ထည့်လို့ရပါတယ်။

if ( post_password_required() ) { ?>
<p>This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
?>

ဒီ coding မှာတော့ post_password_required() ဆိုတာ WordPress ရဲ့ function တစ်ခုပါဘဲ။ ဒီ post အတွက် password “လို” သေးလား “မလို” ဘူးလားဆိုတာကို စစ်ဆေးပေးပါတယ်။ “လို” ရင် comments ကို မပြဘဲထားပြီး “မလို” မှ ပြပေးမှာပါ။ (ကျွန်တော်ပြောတဲ့ “လို” “မလို” ဆိုတာ မပေးထားရင် “မလို” သလို ပေးထားပေမယ့် ထည့်ပြီးရင်လည်း “မလို” ပါဘူး။ )
ဒီပေါ်ပိုင်းက security ပိုင်းပေါ့။ အခုမှကျွန်တော်တို့ရဲ့ comments ကို စခေါ်ပါမယ်။

အပိုင်း(၂)
ဒီအပိုင်းကတော့ comments တွေကိုပြတဲ့အပိုင်းပါ။ for loop ကိုသုံးပြီး ပြပါမယ်။ for loop မသုံးဘဲ wp_list_comments(); ဆိုတဲ့ function ကိုတန်းခေါ်ရင်လည်းရပါတယ်။
အရင် comments ရှိမရှိစစ်ဆေးပါမယ်။

<?php if($comments) : ?>
comments များကို ဒီနေရာမှာ ပြပါမယ်။
<?php else : ?>
<p>No comments yet</p>
<?php endif; ?>

<?php if($comments) : ?>
<ol>
<?php foreach($comments as $comment) : ?>
<li id=”comment-<?php comment_ID(); ?>”>
<cite><?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></cite>
<?php comment_text(); ?>
</li>
<?php endforeach; ?>
</ol>
<?php else : ?>
<p>No comments yet</p>
<?php endif; ?>

“comment များကို ဒီနေရာမှာ ပြပါမယ်။” ဆိုတဲ့နေရာမှာ for loop နဲ့ comment တွေကို ပြပေးတာပါ။ <ol> တို့ <li> တို့ရေးထားပုံကိုလည်း သဘောပေါက်မယ် ထင်ပါတယ်။
comment_ID()=> comment id ကို return ပြန်ပေးပါလိမ့်မယ်။
comment_author_link() => သူ့ site နဲ့ link လုပ်ပြီးသား comment ရေးသူရဲ့နာမည်ကို return ပြန်ပေးပါလိမ့်မယ်။
comment_date() => comment ရေးခဲ့တဲ့ date ကို return ပြန်ပေးပါလိမ့်မယ်။
comment_time() => comment ရေးခဲ့တဲ့ အချိန်ကို return ပြန်ပေးပါလိမ့်မယ်။

အပေါ်က coding ကို style အတွက် လိုတာလေးတွေထည့်ပြီး comment ရဲ့ခေါင်းစဉ်လေးတစ်ခုကိုထပ်ဖြည့်လိုက်ပါတယ်။

<?php if($comments) : ?>
<h3 id=”comments_head”>Discussion<?php comments_number(‘ No Comments’, ‘ One Comment’, ‘ % Comments’ );?></h3>
<ol>
<?php foreach($comments as $comment) : ?>
<li id=”comment-<?php comment_ID(); ?>”>
<cite><?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></cite>
<?php comment_text(); ?>
</li>
<?php endforeach; ?>
</ol>
<?php else : ?>
<p>No comments yet</p>
<?php endif; ?>

for loop မသုံးဘဲ အောက်ကလိုရေးချင်ရင်လည်းရပါတယ်။
<?php if ( have_comments() ) : ?>
<h3 id=”comments_head”>Discussion<?php comments_number(‘ No Comments’, ‘ One Comment’, ‘ % Comments’ );?></h3>
<ol>
<?php wp_list_comments(); ?>
</ol>
<?php else : ?>
<p>No comment yet.</p>
<?php endif; ?>

အပိုင်း(၃)

<?php if(comments_open()) : ?>
<?php if(get_option(‘comment_registration’) && !is_user_logged_in() ) : ?>
login ဝင်ရန် လိုအပ်ရင် link ပေးရန်
<?php else : ?>
comment form စတင်ရန်
<?php if ( is_user_logged_in() ) : ?>
login ဝင်ပြီးသားဆိုရင် username ဖော်ပြရန်
<?php else : ?>
login မဝင်ထားရင် username, email, website တို့ရဲ့ text box ပြရန်
<?php endif; ?>
comment text area ကိုဖော်ပြရန်
<?php endif; ?>
<?php else : //if(comments_open()) ?>
comment ဖွင့်မထားကြောင်းရေးရန်
<?php endif; //if(comments_open()) ?>

ပထမဆုံး if တော့ ဒီ post အတွက် comments ဖွင့်ထားလားလို့စစ်ဆေးပါတယ်။ ဖွင့်ထားမှ ကျန်တာတွေလုပ်မှာဖြစ်ပြီး မဖွင့်ထားဘူးဆိုရင်တော့ “comment ဖွင့်မထားကြောင်းရေးရန်” ဆိုတဲနေရာမှာ ရေးထားတဲ့စာကြောင်းကို ပြပါလိမ့်မယ်။
ဒုတိယ if ကတော့ နှစ်ပိုင်းပါပါမယ်။ ပထမဆုံး comment ပေးဖို့အတွက် registion လိုအပ်သလားလို့ အရင်ကြည့်ပါမယ်။ မလိုအပ်ဖူးဆိုရင်း and နဲ့ဆက်ထားတဲ့အတွက် နောက်ကဘာဖြစ်ဖြစ် else အပိုင်းကိုဘဲလုပ်ပါမယ်။ လိုအပ်တယ်ဆိုရင်း နောက်ကအပိုင်းကို ဆက်ကြည့်ပါမယ်။ is_user_logged_in() ကို not ထည့်ထားပါတယ်။ if(!is_user_logged_in() )ဆိုတာ login ဝင်မထားဘူးဆိုရင် “login ဝင်ရန် လိုအပ်ရင် link ပေးရန်” ဆိုတာကို လုပ်မှာဖြစ်ပြီး။ login ဝင်ပြီးသား ဆိုရင်တော့ else အပိုင်းကို ဆက်လုပ်ပါလိမ့်မယ်။
else အပိုင်းမှာတော့ comment form ကိုစတင်ပါမယ်။ ပြီးရင် if တစ်ခါထပ်စစ်ထားပါတယ်။ login ဝင်ပြီးသားလားလို့စစ်ပါမယ်။ login ဝင်ပြီးသားဆိုရင် username တို့ email တို့မဖြည့်ခိုင်းတော့ဘဲ “comment text area ကိုဖော်ပြရန်” ဆိုတဲ့နေရာမှာရှိတာကိုဆက်လုပ်ပါမယ်။ login မဝင်ရသေးရင်တော့ username, email, website တို့ဖြည့်ဖို့ text box တွေရေးပါမယ်။ logic ပိုင်းကတော့ ဒီလောက်ပဲလို့ထင်ပါတယ်။ ကျန်တာတွေကတော့ html နဲ့ သုံးထားတဲ့ template tag တွေလေ့လာလိုက်ရင်ရမယ်ထင်ပါတယ်။ အောက်မှာ coding ကိုဖော်ပြထားပါတယ်။

<?php if(comments_open()) : ?>
<?php if(get_option(‘comment_registration’) && !is_user_logged_in() ) : ?>
<p>You must be <a href=”<?php echo wp_login_url( get_permalink() ); ?>”>logged in</a> to post a comment.</p>
<?php else : ?>
<form action=”<?php echo get_option(‘siteurl’); ?>/wp-comments-post.php” method=”post” id=”commentform”>
<?php if ( is_user_logged_in() ) : ?>
<p>Logged in as <a href=”<?php echo get_option(‘siteurl’); ?>/wp-admin/profile.php”><?php echo $user_identity; ?></a>. <a href=”<?php echo wp_logout_url(get_permalink()); ?>” title=”Log out of this account”>Log out &raquo;</a></p>
<?php else : ?>
<p><input type=”text” name=”author” id=”author” value=”<?php echo esc_attr($comment_author); ?>” size=”22″ tabindex=”1″ />
<label for=”author”><small>Name <?php if($req) echo “(required)”; ?></small></label></p>
<p><input type=”text” name=”email” id=”email” value=”<?php echo esc_attr($comment_author_email); ?>” size=”22″ tabindex=”2″ />
<label for=”email”><small>Mail (will not be published) <?php if($req) echo “(required)”; ?></small></label></p>
<p><input type=”text” name=”url” id=”url” value=”<?php echo esc_attr($comment_author_url); ?>” size=”22″ tabindex=”3″ />
<label for=”url”><small>Website</small></label></p>
<?php endif; ?>
<p><textarea name=”comment” id=”comment” cols=”100%” rows=”10″ tabindex=”4″></textarea></p>
<p><input name=”submit” type=”submit” id=”submit” tabindex=”5″ value=”Submit Comment” />
<?php comment_id_fields(); ?></p>
<?php do_action(‘comment_form’, $post->ID); ?>
</form>
<?php endif; ?>
<?php else : //if(comments_open()) ?>
<p>The comments are closed.</p>
<?php endif; //if(comments_open()) ?>

ဒီ post က wordpress 3 မထွက်ခင်တည်းက ရေးဖြစ်တာ။ အခု WordPress 3 ကထွက်လာတော့ ကြည့်လိုက်တာ။ comment_form() ဆိုတဲ့ function ခေါ်လိုက်တာနဲ့ အပိုင်း 3 ကရေးစရာတောင် မလိုတော့ဘူး။