মঙ্গলবার, ২৩ মে, ২০১৭

কি!! HoT pOsT template বসাতে চাই? হ্যা,আপনার জন্যই!

মহান রাব্বুলআলামিন আল্লাহর দরবারে কোটি কোটি গুন শুক্রিয়া জ্ঞাপন করছি,
পুর্ণ সুস্থতা সহকারে আপনাদের সম্মুখে গুরুত্বপুর্ণ টিউন নিয়ে উপস্থিত হতে পারার জন্য।

যাদের সাইটে Hot Post টেম্পলেট নেই বা কাজ করেনা তারা এখন Hot Post টেম্পলেট বসিয়ে নিন।
নিচের কোড গুলো কপি করে index.php এ Featured Post এর নিচে বা যেখানে ইচ্ছা বসিয়ে দিন।
.
.
Hot Post template code:
<div class=”block_posts”><h2>Hot posts</h2><ul class=”rpul”>
<?php $args = array(
‘date_query’ => array( array( ‘after’ => ‘-5 days’ ) ),
‘post_type’ => ‘post’,
‘posts_per_page’ => 4,
‘meta_key’ => ‘post_views_count’,
‘orderby’ => ‘meta_value_num’,
‘order’ => ‘DESC’);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<li><?php $thumbnail = get_template_directory_uri().”/img/no-image.png”;
if ( has_post_thumbnail() ) {
the_post_thumbnail(‘featured’,array(“class” => “featured_image”));
} else {
echo ‘<img width=”60″ height=”60″ src=’.$thumbnail.’ class=”featured_image” alt=”noimage” />’;
} ?>
<a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a>
<p><?php the_time(‘M j, Y’); ?> | <?php comments_popup_link( ‘No Comments’ , ‘1 Comment’ , ‘% Comments’ ); ?> | <?php echo getPostViews(get_the_ID()); ?></p>
</li>
<?php
endwhile;
else : get_template_part(‘post’, ‘noresults’);
endif; ?> <?php wp_reset_query(); ?>
</ul>
</div>
.
.
এইটুকু শেষ হলে পরে আপনার থিম এর Function.php তে যান। সেখানে পোস্ট ভিও কাউন্ট নামের কোনো ফাংশন আছে কিনা। থাকলে আর কিছু করতে হবেনা।
আর না থাকলে নিচের কোডগুলো বসিয়ে দিন।
Post view counter code:
/* View Count */
function getPostViews( $postID ){
$count_key = ‘post_views_count’ ;
$count = get_post_meta ( $postID , $count_key , true );
if ($count ==”){
delete_post_meta ( $postID , $count_key );
add_post_meta ($postID , $count_key, ‘0’ );
return “0 View” ;
}
return $count .’ Views’ ;
}
function setPostViews ( $postID ) {
$count_key = ‘post_views_count’ ;
$count = get_post_meta ( $postID , $count_key , true );
if ($count ==”){
$count = 0 ;
delete_post_meta ( $postID , $count_key );
add_post_meta ($postID , $count_key, ‘0’ );
} else{
$count ++;
update_post_meta ($postID , $count_key , $count );
} }
.
.
Hot Post টেম্পলেট টির css ট্রিকবডি থিম এই আছে। না থাকলে ইচ্ছে মতে কাস্টমাইজড করে নিন।
.
.
ভালো থাকবেন।।

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

আলহামদুলিল্লাহ! বেশ উপযোগী ছিলো।