Postviews ayar ekranı
%VIEW_COUNT% viewsSingle.php görüntüleme kodu
<?php if(function_exists('the_views')) { the_views(); } ?> 3
●256
<?php
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 okunma";
}
return $count.' okunma';
}
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);
}
}
?>Tema okunma sayacının görüntülenmesini istediğiniz yere aşağıdaki kodu eklemelisiniz.<?php setPostViews(get_the_ID()); ?><?php echo getPostViews(get_the_ID()); ?>Popüler yazıları listelemek için aşağıdaki kodları kullanabilirsiniz.
<?php
query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC&posts_per_page=10');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile; endif;
wp_reset_query();
?>Kaç adet yazı listelenmesini istiyorsanız post per page kısmından ayarlayabilirsiniz.