Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-04-18 06:44:03

Summer
Member
Registered: 2018-01-29
Posts: 60

The number of hits on the article.

The current solution is: the plug-in reads the log.
Is it possible to add article click (view) quantity values in database article form?
This can be used to quickly call tags, but also reduce the burden on the server.

Offline

#2 2018-04-18 07:31:04

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: The number of hits on the article.

Maybe dzd_counter_view

Cheers.

Offline

#3 2018-04-19 02:55:18

Summer
Member
Registered: 2018-01-29
Posts: 60

Re: The number of hits on the article.

Dragondz wrote #311169:

Maybe dzd_counter_view

Cheers.

hi,This plugin does not work in 4.7dev?

Offline

#4 2018-04-19 04:42:38

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: The number of hits on the article.

It works in my tests but perhaps you’re not using it correctly as the instructions aren’t very clear. Try this:

  1. Create a custom field called countxx in Admin › Preferences › Custom fields (or with glz_custom_fields if you are using that).
  2. Edit your article and put the starting number in it, e.g. 1 and save.
  3. In the article form that shows for your individual article, or in the if_individual_article portion of the default article form, put <txp:dzd_counter_view />. That will advance the counter by one when the page is viewed.
  4. Put <txp:custom_field name="countxx" /> somewhere in your form after dzd_counter_view to display the current count on the page if you want to.

In the standard setup, the custom field needs to be called countxx, but if you want to use a different custom field for the counter, you can do that too by specifying the attribute <txp:dzd_counter_view custom_field="my_custom_field_name" />. You need to change txp:custom_field too.

In the standard setup, the counter will only show on articles where you add a starting count number in step 2. This allows you to add counters to selected articles only. If you leave the custom field blank, nothing shows. If you want to add a counter to all articles and not have to add the starting value manually to each article in step 2, you can use the attribute force="1" and the plugin will start the counter custom field at zero if it doesn’t already contain a number.

Here’s an example using the standard default article form …

<txp:if_individual_article>
        <h1 itemprop="headline">
            <txp:title />
        </h1>
        <txp:dzd_counter_view custom_field="pageviews" /> 
        <p class="pageviews">Pageviews: <txp:custom_field name="pageviews" /></p>
    <txp:else />
        <h1 itemprop="headline">
            <a href="<txp:permlink />" itemprop="url">
                <txp:title />
            </a>
        </h1>
    </txp:if_individual_article>
…

… using a custom field named pageviews instead of customxx.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2018-04-19 07:17:27

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: The number of hits on the article.

Hi, i will try to improve the explanation!

Thanks Jakob for giving this detailed examples. can i add then to the plugin help ?

The code is on github now : https://github.com/dragondz/dzdplugin

Cheers.

Offline

#6 2018-04-19 22:32:17

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: The number of hits on the article.

Hi Dragondz, Thanks for putting it on GitHub. I’ll fork that and try and send you a Pull Request fairly soon with some edits to the help.

I also thought it might be useful to have a reset attribute and will try and add that along with the tag registration code.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2018-04-21 09:12:40

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: The number of hits on the article.

Thanks Jakob, plugin updated and released.

dzd_counter_view

Offline

#8 2018-04-21 13:12:57

Summer
Member
Registered: 2018-01-29
Posts: 60

Re: The number of hits on the article.

Thanks Jakob,
Dragondz.

Offline

#9 2018-07-20 15:19:03

Summer
Member
Registered: 2018-01-29
Posts: 60

Re: The number of hits on the article.

hi

jakob wrote #311236:

Hi Dragondz, Thanks for putting it on GitHub. I’ll fork that and try and send you a Pull Request fairly soon with some edits to the help.

I also thought it might be useful to have a reset attribute and will try and add that along with the tag registration code.

hi jakob I want the initial number of the article click to be 1, where should I modify?

Offline

#10 2018-07-20 15:47:22

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: The number of hits on the article.

Summer wrote #313099:

hi

hi jakob I want the initial number of the article click to be 1, where should I modify?

Try using the attribute reset="1".


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB