Created
February 10, 2015 16:01
-
-
Save akinayturan/b83e3ea103c6c930d70c to your computer and use it in GitHub Desktop.
WP ~ Eklentisiz Yazı Okunma Sayısı & Popüler Yazıları Gösterme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//WP ~ Eklentisiz Yazı Okunma Sayısı Ve Popüler Yazıları Gösterme //epfarki.com | |
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); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php setPostViews(get_the_ID()); ?><?php echo getPostViews(get_the_ID()); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment