Views Counter

Views Counter (VC) is a small plugin for WordPress that helps you to easily track how many times your post page was viewed and by what quantity of visitors.

You can see it in action at this blog right under every post:

VC_example

It’s very flexible and you can tune it easily. No more words, but instructions.

Hooray! Hooray! Views Counter v. 0.10 by Cryonyx is available now. Download →

Attention: Please, read carefully migration instruction and release notes for this version of VC if you are upgrading from previous ones!

Installation

  • Download ZIP archive of the latest version;
  • Unpack it on your computer;
  • Upload folder ‘vc‘ to your plugins directory (usually situated in /wp-content/plugins);
  • Turn VC on at your ‘Plugins’ page
  • Tune it and enjoy :)

A couple of words about upgrading VC from version 0.0x to 0.1x:

  • Deactivate VC at plugins page
  • Backup table “<table_prefix>views_counter”
  • Remove viewscounter.php and folder “vc” from your plugins directory
  • Unzip this archive and place folder “vc” to your plugins directory
  • Activate VC at plugins page

That’s all about installation. Let’s go for…

Tuning

At the ‘Options’ page go to the ‘Views Counter‘ subpage. There you can set up most common options of the plugin. Tweaking of VC could be performed through the usage of vc_get_stats function, but about this a bit more later.

General options

  • Do you want statistics to be displayed at your weblog?
    This option determines whether you use standard mechanism of inserting VC’s code into the page or much advanced, with the usage of vc_get_stats. If a standard approach is being used, then VC inserts its statistics’ string directly below the content of every post.
    Important: No matter what method you use, VC will register every visitor until being turned off at the ‘Plugins’ page. This option only helps you to tweak the output of VC.
  • Should I also display and track views of posts on the main page?
    This one lets you to display statistics not only at post’s single pages, but at the main one, too, just below the excerpts of posts (this way I do at my own blog).
  • May I place the small logo icon at the beginning of the line to thank the author of the plugin?
    If you want to support this project, please turn this option on and just in the beginning of every VC’s statistic line you’ll see a small pretty arrow – logo icon of VC (see it in the picture above). Also you if you use VC you may email a link to your weblog and I place it in a page of VC’s users ))

Text parsing options

In this section you can define how the VC’s statistic line will be displayed. Normally, the line consists of the following elements:

  • Beginning
  • Views counter
  • Views counter’s text
  • Prepositions
  • Visitors counter
  • Visitors counter’s text

You can see it in the image below:

VC_example

Of course, some elements may be omitted in settngs. It depends on the language. E.g., in English, we have to place a preposition ‘by’, but in Russian there won’t be any preposition. That’s why you may leave nearly all the fields in this section of options empty.

Additional options

In this section some additional options are listed.

  • Display stats on posts’ management page
    This option determines whether additional column at the posts’ management page is displayed. See example:
    VC v.0.04 New Feature

    The header of the column is a direct hyperlink to this option (at VC’s options page), so you can change its behavior in three clicks. Numbers shown in the column are views/visitors counters. Roll the mouse pointer over it, and you can see the hint describing figures in human language :)
    Important! This feature uses specifical hooks of WP 2.0.4. Maybe they’re present in previous versions, but I don’t know exactly, so it may not work on WP with version below the 2.0.
  • Command line (cmd>)
    This feature introduced in VC v. 0.10 was designed for providing a number of ‘special’ features in VC. By the moment following commands are available:

    • -place
      If you are not using vc_get_stats() function, then this command will let you choose, where VC’s text is to be placed – before or after the content of the post. Only two values are available: top and bottom. Examples:
      -place=top
      -place=bottom
    • -debug
      This command is linked with logger functionality introduced in VC v. 0.10. If you feel that VC does not work correctly, then you just write:
      -debug=on
      After that all the important operations performed by VC will be logged to file ‘vc.log’ placed in ‘vc’ directory. But be careful! If you have popular blog, this file can grow rather fast (e.g., after I had run through all the posts of my blog one time, I’d got log file of 1.3MB).

    Of course, commands can be put together, but in this case they must be separated with one space. Example:
    -place=top -debug=on

Tweaking

This section if for those who are able to write a WP-Theme by themselves or at least make corrections to the existing one. The talk is about the vc_get_stats function. The declaration of it is as following:
function vc_get_stats(
$text_before = 'Viewed',
$human_count_text = 'times',
$human_ct_function = NULL,
$preposition = 'by',
$human_viewers_text = 'visitors',
$human_vt_function = NULL,
$with_icon = 0
)

As you can see, many of the parameters are optional. But I strongly recommend you to set your own values for them. Let’s walk around them and explain what thay mean.

  • $text_before – corresponds to the ‘beginning‘ in the above mentioned scheme of statistic line.
  • $human_count_text – corresponds to the ‘views counter’s text‘. Important: sets only one caption for all possible values of counter. To change this you may use the following parameter.
  • $human_ct_function – lets you to assign your own handler to the views counter. In many languages to different numbers correspond different words, e.g., 1 view, but 7 views. Through this param you should pass the name of your function, which has the following format:
    function your_handler( $the_number_of_views )
  • $preposition – think there’s no need to explain.
  • $human_viewers_text and $human_vt_function – the same situation as with $human_count_text and $human_ct_function.
  • $with_icon – you should pass ’1′ for to display the logo icon and help the project, or something else or just leave is empty for not to display. Note: you can place the logo in any place by calling the vc_get_icon function, which has no params to pass to.

Well, this is all. No so difficult, yeah? :) I have a lot of plans for developing this small project, so check this page regularly.

Important notes

  • VC uses its own table in database called ‘table_prefixvc_data’ (depends on system settings. E.g., on my blog this one is ‘wp_vc_data‘). It consists of two columns: posts’s id and compressed statistical data (it can be easily deciphered, as it has following format: [Number_Of_Views_in_HEX]/[IP1_in_HEX]/…/[IPn_in_HEX]). If your weblog is popular, please take care that you have enough diskspace on server to keep the database.
  • VC is developed under GNU GPL license, so you can help me to improve it. But, please, inform me if you want to do something rather great with VC, because it may be non-compatible with the newer version of VC.

Notes on releases

  • VC v.0.10
    Second stable version.
    Code was fully rewritten and optimized. Now it runs pretty faster (after all the posts’ statistics has converted to new format).
    Attention! VC v.0.10 uses PHP 5 objects, so it won’t work at any older version of PHP (e.g., PHP 4.*).
    New functionality:

    • Logging of main operations performed by VC (optional);
    • Command line at options page
    • Compression of statistical data (now it is stored in table <table_prefix>vc_data – be careful!)

    Update notes: See above.
    Bug fixed: Wrong link at manage posts’ page.
    Important note: Please pay attention that your statistical data is converted to new format only if the post it is linked to is viewed by anybody. That means you’d better run through all of your posts for convert the data or wait until I write special conversion patch for VC.

    Archive

  • VC v.0.07
    Bug fixed: annoying notification of plugin deactivation removed.
    Update notes: no. Just copy contents of the archive to the plugins directory, replacing old files.

    Archive

  • VC v.0.06
    Critical! This version of VC is marked as critical for update. Some significant changes were made to VC v.0.05.
    Bug fixed: Previous versions of VC didn’t work correctly when vc_get_stats function was used.
    Update notes: copy contents of the archive to the plugins directory, replacing old files. If you want use VC through vc_get_stats function, be sure you have the correspondent option enabled like this:

    VC_example

    Archive
  • VC v.0.05
    Critical! This version of VC is marked as critical for update. Some significant changes were made to VC v.0.04.
    Bug fixed: there was a bug linked to displaying stats for non-viewed posts.
    Structure changes: VC was optimized and separated into several files for to ease developing and using of it.
    Update notes: no. Just copy contents of the archive to the plugins directory, replacing old files.
    Archive
  • VC v.0.04
    New feature: Information about views’ and visitors’ counters added to the posts’ management page.
    Important! Tested only on WP 2.0.4 and uses some hooks that may be not present in previous versions.
    Update notes: no. Just copy contents of the archive to the plugins directory, replacing old files.
    Archive
  • VC v.0.03
    Bug fixed: now visits of the posts’ author are not taken into account. (Only if the author is logged in! :))
    Update notes: no. Just copy contents of the archive to the plugins directory, replacing old files.
    Archive
  • VC v.0.02
    First stable version of VC.
    Archive

79 thoughts on “Views Counter”

  1. Hi Cryonyx,
    Thx for making this plugin available for everyone.
    Unfortunately I get this erro on WP 2.3.3 (I hv replaced my website with “xyz” for privacy purpose)

    Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /home/xyz/public_html/xyz.com/wp-content/plugins/vc/vc.class.php on line 9

    Any advise on how what I might be doing wrong?
    Thanks!

  2. Hi, Australia!
    The problem 90% probability is that you use PHP 4, which doesn’t support classes in the way the latest version of VC requires. Try using VC 0.071 (look the comment #40 above).

  3. Thank U for your prompt reply, Cryonyx!
    I downloaded VC v.0.07 as per your advice and it worked straight away.
    Thanks again!

  4. Just a couple of questions, is it compatible with wp 2.5?
    Can I edit the views count for each post so counting doesn’t start from 0?

    thanks

  5. James
    1. Saying truth, I haven’t test it. Probably. In WP 2.5, as far as I know, only admin-pane has changed dramatically. The basic functionality remained the same. Then all should work good;

    2. Yes, 4 sure. But it’s not that easy: you should know the HEX encoding and be acquainted with MySQL. If you are that guy, then open the table wp_vc_data, find the entry with the necessary ID and edit the first block of symbols before slash. For example:

    Entry ID: 1
    Views: 1
    IPs: doesn’t matter (should be at least one)

    You want to change the indicator to, say, 2500. Then you should change the “data” field to:
    9C4/…
    (where “…” should be replaced with encoded IPs).

    That’s it. The indicator shows now 2500 views.

  6. Kombor
    Really? That’s good news :) Thank you!

    BTW, the new version of VC is ongoing. I plan to release it in the middle of June.

  7. hello…
    i have benefited by using vc0.02 for the last two years.
    however it does not display on ‘pages’ like it does in ‘posts’.
    any reason this is so?
    …pR

  8. Great plugin. I would however, like the counter to show at the bottom of the page. Just like how the counter is set for every post, I’d like just one for the page. Help?

  9. Is there any news on a new version of this plugin? I would like to use it. I have wordpress version 2.6.2. It’s a great plugin , i can’t find anybody who has a simular plugin.

  10. Hi,
    I love the plugin and got the easy option to show in the posts management.
    But I am trying to add a line to the post next to the author showing the views and can not seem to get it to display.

    is this all I need to add to my theme ?

    function vc_get_stats(
    $text_before = ‘Viewed’,
    $human_count_text = ‘times’,
    $human_ct_function = NULL,
    $preposition = ‘by’,
    $human_viewers_text = ‘visitors’,
    $human_vt_function = NULL,
    $with_icon = 0
    )

    When I do I get no output.

    Thanks in advance
    Lewis

  11. PS: И по моему для всех постов показывает одно и тоже значение, какую последнею версию вордпресса ты юзал?

  12. прощу прощения, первый пост не опубликовался, иконка справа от счетчика не отображается (в меню выбрал показывать) но там просто ссылка на ваш блог. Версия вордпресса WordPress 2.8.5.

    не подскажете как быть?

  13. Хм. Странно, что иконка не отображается. Убедись, что она находится в папке с плагином.
    Что касается версии WP, то плагин работает на любой начиная с 1.2 – он использует только базисный функционал WP, который не менялся уже очень давно.

    Что касается одного и того же значения для всех постов – просто нужно немного времени подождать, пока пользователи перестанут читать только главную страницу и полезут по самим постам. Ещё счётчик может не отображаться вовсе сразу после установки, поскольку просмотры админа не учитываются.

  14. WordPress 2.8.6. тема WordPress Constructor Theme 0.6.2
    вроде сделал все как написано.
    создал папочку. скопировал. активировал.
    а статистику так и не показывает :(
    уже и в темплейт пытался функцию тыкать.
    есть идеи что я делаю не так?

  15. Версия WP 2.9.1 после добавления отображает <<<<<<>>>>>> .r740
    после деактивации эти знаки не исчезли ….. плиз, помогите, как быть?

  16. “Ещё счётчик может не отображаться вовсе сразу после установки, поскольку просмотры админа не учитываются” Если выйти из браузера или открыть в другом браузере незалогинившись то можно увидеть.

  17. @jasmine

    Скорее всего, это глюк не этого плагина. Какой адрес ресурса? Какие ещё плагины установлены?

    2 Брен
    В первом случае это возможно только, если броузер стирает куки.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>