how to show number of views for each post/page in wordpress?

5 views
Skip to first unread message

ovivankenobi

unread,
Jan 31, 2010, 7:28:47 AM1/31/10
to firestats-users
After reading hte wiki and finding the api page, I guess I need to use
this function: fs_api_get_hit_count but I can't seem to get it right.

I'd like to show something like: viewed: XXX jsut show the total
number of views for each page and post.

can someone review this code for me please?

<?php
if (defined('FS_API'))
{
echo "Number of times this page was viewed: ". fs_api_get_hit_count
(,true,the_permalink(););
}
?>

the above code doesn't work for me :-( I admit I suck at php so pelase
help me out here.
Also I do not know, what the first 2 parameters represent: the first
one was 100 restricting the number of views to the last 100 days - can
I leave it empty to show data from all times?

What is the 2nd one? true? what does it influence?

Omry Yadan

unread,
Jan 31, 2010, 8:56:05 AM1/31/10
to firesta...@googlegroups.com
the example was a bit outdated.
you should use fs_api_get_page_views, which is documented here :
http://firestats.cc/wiki/API

/*
Returns the number of pages displayed in the specified time period.
days_ago is an optional parameter which specifies how many days ago to start counting.
if days_ago is not specified, the count will begin when you installed FireStats.
site_id : see comment at the start of the file
url: see comment at the start of the file
*/
functionfs_api_get_page_views($days_ago=NULL,$site_id=true,$url=null)


if you don't want to specify days_ago, pass NULL instead, like:

echo "Number of times this page was viewed: ". fs_api_get_hit_count(NULL,true,the_permalink());

note that you had an extra ; after the_permalink().


the site id parameter (second true in your call) is documented at the page.
you probably want to use true here.

ovivankenobi

unread,
Jan 31, 2010, 4:28:39 PM1/31/10
to firestats-users
thanks.

almost there. I tried this:

<?php
if (defined('FS_API'))
{

echo fs_api_get_page_views(NULL,1,the_permalink())." vizualizari";
}

?>

the out put is this:

http://zice.ro/informatii/ce-fel-de-articole-si-tutoriale-va-doriti-de-la-noi/122921
vizualizari

It basically prints out the current permalink followed by the number
of hits.
What am I doing wrong here? It shouldn't print out the permalink just
use it to show only the hits for the current page/post.

Omry Yadan

unread,
Feb 2, 2010, 1:37:12 AM2/2/10
to firesta...@googlegroups.com
I am guessing that the_permalink() is doing the printing.
try to use get_permalink($post->ID) instead,
Assuming you call it in the context of a post (if not ask in WordPress
forums).

ovivankenobi

unread,
Feb 2, 2010, 9:27:56 AM2/2/10
to firestats-users
thx, works perfectly
Reply all
Reply to author
Forward
0 new messages