• 06-03-2019, 00:34:49
    #1
    Merhaba arkadaşlar,

    Wordpress sitem için basit bir php koduna ihtiyacım var, sayfamda bir eklenti var, bu eklenti ile sayfama kaç kişi görüntülenme almış bunu sayıyor.

    Örnek olarak kod burada:

     <div class="post-views post-12 entry-meta">
    <span class="post-views-icon dashicons dashicons-chart-bar"></span>
    <span class="post-views-label">Post Views: </span>
     <span class="post-views-count">6</span>
    Bu 6 rakamı devamlı değişiyor, Sayfa görüntülenme aldıkça 6 rakamı sürekli güncelleniyor.. Ben burdaki veriyi , yani güncel rakamı header'de bir bölümde php ile göstermek istiyorum.

    Yani sadece o son rakamı istediğim bir yerde php ile göstermek istiyorum. Aslında iki veride aynı sayfada olacak, istediğim, headerde onu bir kod içine eklemem gerekiyor.


    Bilenler yardım ederse, sevinirim + Like,

    Teşekkürler Şimdiden..
  • 06-03-2019, 00:55:51
    #2
    Merhaba. Eklenti dosyalarini acin ve
    add_action('wp_head', 'function_name');
    gibi bir kod arayin ve buradaki function_name ismindaki parametrenin fonksiyon halini arayin yani
    function function_name(){}
    daha sonra bu fonksiyon icinde
    <span class="post-views-count">$degisken</span>
    seklinde bir kod arayin ve bu degiskeni isterseniz global istersen sabit degiskene aktarip daha sonra tema dosyanizda gosterin.
  • 06-03-2019, 02:05:07
    #3
    Teşekkürler hocam,

    kodu buldum,

    ve bu sekilde ekledim.


    <span class="post-views-count">$views</span

    ancak o rakamları göstermedi. birşey yazmamişim gibi. anlamadım.
  • 06-03-2019, 02:07:58
    #4
    mechulsun adlı üyeden alıntı: mesajı görüntüle
    Teşekkürler hocam,

    kodu buldum,

    ve bu sekilde ekledim.


    <span class="post-views-count">$views</span

    ancak o rakamları göstermedi. birşey yazmamişim gibi. anlamadım.
    kodun oldugu functionu paylasir misin hocam?
  • 06-03-2019, 02:15:03
    #5
    SaidYildiz adlı üyeden alıntı: mesajı görüntüle
    kodun oldugu functionu paylasir misin hocam?
    o kodu, pluginin içindeki functions isimli dosyadan buldum.. views seklinde denedim. ama olmadı. views seklinde gösterdi yaziyi, php ile baslattim, bu seferde hiçbirşey göstermedi.

    function pvc_post_views( $post_id = 0, $echo = true ) {
    
            // get all data
            $post_id = (int) ( empty( $post_id ) ? get_the_ID() : $post_id );
            $options = Post_Views_Counter()->options['display'];
            $views = pvc_get_post_views( $post_id );
    
            // prepare display
            $label = apply_filters( 'pvc_post_views_label', ( function_exists( 'icl_t' ) ? icl_t( 'Post Views Counter', 'Post Views Label', $options['label'] ) : $options['label'] ), $post_id );
            // get icon
            $icon_class = ( $options['icon_class'] !== '' ? esc_attr( $options['icon_class'] ) : '' );
            // add dashicons class if needed
            $icon_class = strpos( $icon_class, 'dashicons' ) === 0 ? 'dashicons ' . $icon_class : $icon_class;
          
            $icon = apply_filters( 'pvc_post_views_icon', '<span class="post-views-icon ' . $icon_class . '"></span>', $post_id );
    
            $html = apply_filters(
                'pvc_post_views_html', '<div class="post-views post-' . $post_id . ' entry-meta">
                ' . ($options['display_style']['icon'] && $icon_class !== '' ? $icon : '') . '
                ' . ($options['display_style']['text'] ? '<span class="post-views-label">' . $label . ' </span>' : '') . '
                <span class="post-views-count">' . number_format_i18n( $views ) . '</span>
                </div>', $post_id, $views, $label, $icon
            );
    
            if ( $echo )
                echo $html;
            else
                return $html;
        }
    
    }
  • 06-03-2019, 02:41:17
    #6
    pvc_get_post_views( get_the_ID() )
    bu sekilde kullanir misin hocam loopun icinde mi disinda mi bir de bu onemli
  • 06-03-2019, 03:37:30
    #7
    EDİT:

    Hocam, tekrar teşekkür ederim,

    sorunu çözdüm.

    bu şekilde yaptım.


    <?php if( function_exists('pvc_get_post_views') ) echo pvc_get_post_views( $post->ID); ?>