Clear Template Hits Plugin

Sunday, September 18, 2005

I whipped up a very simple plugin today that resets the hit counters for all templates within a template group. I wrote it because it’s much faster than using the control panel to manually update the hit counter for every template. It works best with the Cron plugin.

Download version 1.0 here. Unzip and upload the plugin file to your system/plugins folder. Documentation and examples are inside the plugin file, and I’ve copied them below.

ABOUT

This plugin resets the template hit counters. It works with the Cron plugin and also by itself. The plugin resets the hit counters for all templates within a template group and not individual templates. You can specify which template groups to reset and the number to which to reset the hits to.

PARAMETERS

which – the names of the template groups you want to reset the hits of. You can specify multiple template groups by separating the names with the pipe | character. Use the word ‘all’ to specify all template groups. By default the plugin will clear hits on all template groups.

num – the number which you want to reset the hits to. By default this number is set to 0.

EXAMPLE

The following will set the hits for the templates in the template group ‘weblog’ to 0 at 5am every morning. This example uses the Cron plugin.

{exp:cron minute="0" hour="5" plugin="clear_template_hits" which="weblog"}{/exp:cron}

Here’s the same example without using the Cron plugin. The plugin will reset hits whenever you access the template that contains the code.

{exp:clear_template_hits which="weblog"}

You can also output a message saying that the plugin worked. This example uses the Cron plugin, but in a different way from the first example. The following will output ‘Template hits have been cleared!’ every morning at 5am.


{exp:cron minute="0" hour="5" parse="inward"}
{exp:clear_template_hits which="weblog"}Template hits have been cleared!{/exp:clear_template_hits}
{/exp:cron}

ELSEWHERE

Comments & Trackbacks

Post a comment.

The trackback URL for this entry is:

Post a Comment

Commenting is not available in this weblog entry.

Live Preview

Avatar

Comment Author

Jul 31 2010 @ 04:22 PM