• Hello!

    I’ve run into a slight problem … I want to list the most read articles on my front page (the same ways recent posts etc. are displayed “normally”) but I don’t think WordPress has built in functionality for doing that.

    I use Counterize for statistics and I don’t know, maybe I could somehow use that in order to create my list?

Viewing 8 replies - 1 through 8 (of 8 total)
  • I don’t think WordPress has built in functionality for doing that.

    You’re right. It doesn’t.

    I don’t know anything about Counterize but whatever you use, it’s likely to be a pretty big task.

    you have to install some specific plugins. search for them.

    Thread Starter iafiawik

    (@iafiawik)

    I have searched for plugins but I haven’t found any that would do the job.

    And yes, it’s likely to be a very big task. I’ll have to aks myself if it’s worth it. I’m a web developer but I have never built anything specificially for WordPress :/

    You might need to use something like http://wordpress.org/extend/plugins/popular-posts-plugin/ that has a ‘template tag’ <?php popular_posts(); ?> to display those popular posts.

    Thread Starter iafiawik

    (@iafiawik)

    Thanks!

    That’s actually a great plugin …

    The only problem I have is that it shows total amount of hits, not the unique ones … meaning that if I refresh the page 1584 times while reading a post that post will be the “most read” (which isn’t very close to reality). I was hoping there would be an option for choosing between unique or total hits, but I cannot seem to find one 🙁

    FWIW i cobbled together the functionality to do this on my own site using a “?list=most_viewed” GET parameter to turn it on using this code in my functions.php

    if ($_GET['list']=="most_viewed")
    {	add_filter('posts_fields', 		'list_viewed_posts_fields');
    	add_filter('posts_join_paged', 	'list_viewed_posts_join_paged');
    	add_filter('posts_orderby', 	'most_viewed_posts_orderby');
    }
    
    function list_viewed_posts_fields($fields)
    {	return $fields.", 0+meta_value as total_views"; }
    
    function list_viewed_posts_join_paged($join)
    {	global $wpdb;
    	return $join." INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key='views') ";
    }
    
    function most_viewed_posts_orderby($orderby)
    {	return "total_views desc"; }

    which uses a meta_field ‘views’ that stores hits for a post

    Thread Starter iafiawik

    (@iafiawik)

    Oh, that would be great … If only I knew how to use it 😛

    Could you explain a little more detailed? I don’t know what I thought would happen, but … um, I haven’t noticed any difference at all after putting that piece of code in functions.php.

    Any more information on this one?

    Thread Starter iafiawik

    (@iafiawik)

    All right. Finally I found my ‘own’ soloution. I downloaded http://wordpress.org/extend/plugins/most-read-posts-in-xx-days/ which actually stores unique hits per post.

    Problem was that I needed to inform my admins first day of each month what the previous months statistics look like, so I somehow had to restore the values the first date of each month. So basically what I did was creating another table which only contains one field storing last truncate time. Each time the website is visited by someone WordPress checks wheather or not today’s month is later than the one stored in the additional table. If so, the table storing the unique hits has to be restored. And after that I just simple sent an e-mail containing the statistics to my admins (and inserted today’s time into the additional table, of course). And yes, it actually works. Sweet! So far so good.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘List most read articles’ is closed to new replies.