jueves, 21 de julio de 2011

Count Page Hits in WordPress

This is just a little snippet of code I wrote to count the number of hits on a specific page. I only wanted it to work on single post pages so I included the is_single() conditional tag.

function count_page_hits() {    if(is_single()) {  
     global $post; 
     $count = get_post_meta($post->ID, 'count_page_hits', true);
    $newcount = $count + 1; 
    update_post_meta($post->ID, 'count_page_hits', $newcount);} }
    add_action('wp_head', 'count_page_hits');


Enlace al articulo Aqui

No hay comentarios:

Publicar un comentario