• 30-12-2015, 20:28:36
    #1
    Postviews eklentisini kurdum ancak okuma sayıları çalışmıyor kodlarım şu şekilde

    Postviews ayar ekranı
    %VIEW_COUNT% views
    Single.php görüntüleme kodu
    <?php if(function_exists('the_views')) { the_views(); } ?>
  • 01-01-2016, 01:27:09
    #2
    Eklenti kullanmadan yapsan daha iyi olur. Aşağıda nasıl kullanacağın ile ilgili gerekli açıklama mevcuttur.

    Function.php Eklenecek Kodlar.
    <?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.
  • 01-01-2016, 01:29:23
    #3
    Cache eklentisi olarak ne kullanıyorsun ?
  • 03-01-2016, 00:13:52
    #4
    footera bu <?php wp_footer(); ?> kodu ve headera da <?php wp_head(); ?> bu kodu eklersen çalışır. Ben sorunu bu şekilde çözdüm ve cache eklentisi de çalışıyor.