Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
# of posts since last visit
I’m wondering if there’s a way to set a cookie so that i can tell people how many blog posts have been added since their last visit?
so i need to know about setting the cookie, and then displaying # of articles added since that cookie date.
Last edited by mrtunes (2010-05-13 14:26:57)
Offline
Re: # of posts since last visit
I was trying to do this with the chs_cookie plugin but the plugin doesn’t seem to be working.
You can count the articles with rvm_counter and set a cookie with the value of the counter then subtract the cookie value from the counter value to get articles since.
Here’s the code I expected to work but it doesn’t and I’m blaming chs_cookie.
<txp:article_custom>
<!--<txp:rvm_counter />-->
</txp:article_custom>
<p>article count is <txp:rvm_counter step="0" /></p>
<txp:chs_cookie_exists cookie="articleCount">
<p>cookie value = <txp:chs_echo_cookie cookie="articleCount"></p>
<p>There have been <txp:rvm_counter offset='-<txp:chs_echo_cookie cookie="articleCount">' /> since your last visit.</p>
</txp:chs_cookie_exists>
<txp:chs_set_cookie cookie="articleCount" value='<txp:rvm_counter step="0" />'>
Last edited by MattD (2010-05-13 16:28:31)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: # of posts since last visit
Cool well it looks like you’re on the right path at least !
Offline
Re: # of posts since last visit
If someone knows how to get the value of rvm_counter in within a <txp:php>
tag then you could do it this way:
<txp:article_custom>
<!--<txp:rvm_counter />-->
</txp:article_custom>
<p>article count is <txp:rvm_counter step="0" /></p>
<p>cookie value = 2</p>
<p>There have been <txp:rvm_counter offset='-<txp:php>echo $_COOKIE['articleCount']+1;</txp:php>' /> since your last visit.</p>
<txp:php>
// set the cookies
setcookie("articleCount", "VALUE_FROM_RVM_COUNTER");
</txp:php>
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: # of posts since last visit
MattD wrote:
If someone knows how to get the value of rvm_counter in within a
<txp:php>
tag…
<txp:php>
// set the cookies
setcookie("articleCount", rvm_counter(array('step' => '0')));
</txp:php>
(untested) ??
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: # of posts since last visit
This works, thanks Stef.
<txp:article_custom limit="99999">
<!--<txp:rvm_counter />-->
</txp:article_custom>
<p>article count is <txp:rvm_counter step="0" /></p>
<p>cookie value = <txp:php>echo $_COOKIE['articleCount'];</txp:php></p>
<p>There have been <txp:rvm_counter offset='-<txp:php>echo $_COOKIE['articleCount']+1;</txp:php>' /> since your last visit.</p>
<txp:php>
// set the cookie
setcookie("articleCount", rvm_counter(array('step'=>'0')));
</txp:php>
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: # of posts since last visit
Beware about rvm_counter, as it counts things and keeps the count on the database, and the main issue with that is that concurrent visitors/request may alter the counter in unexpected manners. Some years ago, I used rvm_counter to count articles being displayed on a page, and that use that number to do some “complex” maths and feed the results to JS and CSS on the fly. Everything worked ok on my local server, as I was the only one hitting the pages. But strange behaviors begun when I moved the site to an stage server and both the client and me accessed some pages at the same time. That triggered the “unexpected” behavior, as rvm_counter was being reseted or altered when two or more users hit the same page almost at the same time.
So, I asked ruud about this issue and he was kind to send me a modded version of rvm_counter. This modified version counts things “on the fly”, that is, on memory, and not on the database.
So, with this version you can do exactly the same: count all the articles, save the count on the cookie, and then, on next visit, count all articles again and compare against the cookie.
An alternative to rvm_counter is adi_calc, which can be used for the same purposes.
Offline
Re: # of posts since last visit
Good to know. I’d recommend using either the moded version or adi_calc if that’s the case. I used rvm_counter because I had it installed already. I’d better check and see how I’m using it ;-).
Thanks Julián!
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: # of posts since last visit
Here’s an adi_calc version:
<txp:variable name="articleCount" value="0" />
<txp:article_custom limit="99999"><txp:adi_calc name="articleCount" add="1"/></txp:article_custom>
<p>article count is <txp:variable name="articleCount"/></p>
<p>cookie value = <txp:php>echo $_COOKIE['articleCount'];</txp:php></p>
<txp:variable name="articlesSince" value='<txp:variable name="articleCount"/>'/>
<p>There have been <txp:adi_calc name="articlesSince" subtract='<txp:php>echo $_COOKIE['articleCount'];</txp:php>' display='1'/> since your last visit.</p>
<txp:php>
// set the cookie
setcookie("articleCount", variable(array('name'=>'articleCount')));
</txp:php>
Last edited by MattD (2010-05-13 23:24:14)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: # of posts since last visit
mrtunes, Let me know how you end up implementing this and I’ll do a write up at TXPTips.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: # of posts since last visit
ok will do matt! to make things more interesting i’m planning doing a red little circle over the blog link on my navbar, like an iphone push notification. it will just have the number, and then on rollover it will expand a little to explain that’s how many posts since last visit.
Offline
#12 2010-05-14 19:50:37
- candyman
- Member
- From: Italy
- Registered: 2006-08-08
- Posts: 684
Re: # of posts since last visit
Thanks Matt, I was going to ask for it!
Offline