Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2017-03-11 16:56:39
- bashirnoori
- Member
- From: Afghanistan
- Registered: 2012-10-02
- Posts: 75
making article count to custom field
I want to have article count for each hited article.
I added the following code to default form
, instead of adding 1 count it will add 2 count on each visit which goes wrong count
any good solution for having article count plz
<txp:if_individual_article>
<txp:php>safe_update('textpattern', 'custom_3=custom_3+1', 'ID='.parse('<txp:article_id />'));</txp:php>
</txp:if_individual_article>
Offline
Re: making article count to custom field
Could it be that you have two <txp:article(_custom) />
tags using default
form?
Offline
#3 2017-03-12 04:50:13
- bashirnoori
- Member
- From: Afghanistan
- Registered: 2012-10-02
- Posts: 75
Re: making article count to custom field
i didn’t see any <txp:article ...
or <txp:article_custom ...
on default
form.
but it was works fine for me on txp 4.5.7
Offline
#4 2017-08-15 07:16:08
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 278
Re: making article count to custom field
I’ve the same problem, it add +2 on each visit of article !
Offline
Re: making article count to custom field
A wild guess if you’re absolutely sure there is only txp:article(_custom) tag being processed on your page: could it be because the parser has two passes?
A possible alternative approach: use <txp:page_url type="id" />
(docs) to retrieve the page’s id number at the top of your template (not inside any article tags). If it exists (=an individual page), then use that to update the custom field outside of the txp:article(_custom) container…
TXP Builders – finely-crafted code, design and txp
Offline
Offline
#7 2017-08-16 07:37:34
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 278
Re: making article count to custom field
this is my default page template coes:
<txp:if_search>
<h1>Search Result:</h1>
<txp:output_form form="search_results" />
<txp:else />
<txp:if_category>
<h1><txp:category title="1" /></h1>
<txp:article limit="10" />
<txp:else />
<txp:if_individual_article>
<txp:article />
<txp:else />
<div>my home page template design...</div>
</txp:if_individual_article>
</txp:if_category>
</txp:if_search>
and here is my default form code:
<txp:if_individual_article>
<txp:if_article_category>
<txp:php>safe_update('textpattern', 'custom_3=custom_3+1', 'ID='.parse('<txp:article_id />'));</txp:php>
</txp:if_article_category>
</txp:if_individual_article>
<article class="article">
<txp:if_individual_article>
<h1>
<txp:title />
</h1>
<txp:else />
<h1>
<a href="<txp:permlink />" itemprop="url">
<txp:title />
</a>
</h1>
</txp:if_individual_article>
<div itemprop="articleBody">
<txp:if_article_image>
<div class="innerimg"><txp:article_image /></div>
</txp:if_article_image>
<txp:body />
</div>
</article>
etc: i add echo 'here';
just that echo here on the output.
Note: i did the same way on TXP 4.5.7 , there works fine it will add +1 on each visit of article, but in 4.6.2 it will add +2
Offline
Re: making article count to custom field
etc: i add echo ‘here’; just that echo here on the output.
I think etc wanted to know if the word “here” appears more than once in the html source code produced by textpattern (check the whole source not just what appears on screen). If it does, that would indicate that the code is being executed twice.
An aside: what does <txp:if_article_category>…</txp:if_article_category>
do without any attributes?
TXP Builders – finely-crafted code, design and txp
Offline
Re: making article count to custom field
Can not reproduce with your code, works fine on 4.6.2 for me. I guess there is something else in your default page template?
Offline
#10 2017-08-16 17:20:58
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 278
Re: making article count to custom field
i checked one by one each line and did debug alot, finally i found the issue
i’ve a js plugin for scroll-to-top when i remove that it will works fine (add +1 on each visit of article)
this is the JS
var scrolltotop={
setting: {startline:100, scrollto: 0, scrollduration:500, fadeduration:[500, 100]},
controlHTML: '<img src="images/button-up.png" style="width:40px; height:40px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
controlattrs: {offsetx:15, offsety:15}, //offset of control relative to right/ bottom of window corner
anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
state: {isvisible:false, shouldvisible:false},
scrollup:function(){
if (!this.cssfixedsupport) //if control is positioned using JavaScript
this.$control.css({opacity:0}) //hide control immediately after clicking it
var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
dest=jQuery('#'+dest).offset().top
else
dest=0
this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
},
keepfixed:function(){
var $window=jQuery(window)
var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
this.$control.css({left:controlx+'px', top:controly+'px'})
},
togglecontrol:function(){
var scrolltop=jQuery(window).scrollTop()
if (!this.cssfixedsupport)
this.keepfixed()
this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
if (this.state.shouldvisible && !this.state.isvisible){
this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
this.state.isvisible=true
}
else if (this.state.shouldvisible==false && this.state.isvisible){
this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
this.state.isvisible=false
}
},
init:function(){
jQuery(document).ready(function($){
var mainobj=scrolltotop
var iebrws=document.all
mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
.attr({title:'Scroll Back to Top'})
.click(function(){mainobj.scrollup(); return false})
.appendTo('body')
if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
mainobj.togglecontrol()
$('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
mainobj.scrollup()
return false
})
$(window).bind('scroll resize', function(e){
mainobj.togglecontrol()
})
})
}
}
scrolltotop.init();
Offline
Re: making article count to custom field
:-) Try to give the absolute path to the image src
in
controlHTML: '<img src="images/button-up.png" style="width:40px; height:40px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
Offline
Pages: 1