XF 2.0 {xen:count $posts} equivalent for XF2

BassMan

Well-known member
I'm looking for equivalent to this conditional statement for XF2:

Code:
<xen:if is="{xen:count $posts} > 0" />

Thank you for helping.
 
Actually I'd like to show ad in thread view sidebar position but only if there are 2 or more posts in a thread.
 
Thanks, @Xon , but I would like to show ads in thread view sidebar with that conditional, but does not work right if I wrap it with ad code.
 
Note, the example is a self-closing tag:
Code:
<xf:if is="count($posts) >2" />
which is compiled down to:
PHP:
if (count($posts) >2) { }

You really need:
Code:
<xf:if is="count($posts) >2" >
... ad code...
</xf:if
which compiles down to:
PHP:
if (count($posts) >2) 
{
... ad code...
}
 
You really need:
Exactly what I did, but it's not working in thread view sidebar widget.

Code:
<xf:if is="count($posts) >2" >
... ad code...
</xf:if>

EDIT: actually it throws a syntax error when using it in HTML widget on Thread view: Sidebar position
 
Last edited:
Hm, really can't figure it out...

I need that for my forum before I upgrade it to XF2 and I hope someone can help.

Well, maybe that's for support forum...
 
A specific error may help (with the exact code you're using), but you likely need to get rid of the space between the end of the attribute (") and the close of the tag (>) in your example code.
 
There is no server error. It throws only syntax error when I hit Save for my test ad code this:
HTML:
<xf:if is="count($posts) >2">
<div class="adSense ad_above_content" align="center" style="padding: 30px 0px; border: 1px solid #e4e4e4; border-radius: 5px; background: #3d70d2;">
<div align="center" style="color: #fff;">FMU__thread_view_sidebar</div>
</div>
</xf:if

That's because I don't have > at the end, I guess. If I add this it saves normally, but I don't see it working in front end at all.
 
The $posts return null in the thread view sidebar
1513964219134.webp
1513964294594.webp
You need to pass to the context, add this in the thread_view_sidebar position in thread_view template
Rich (BB code):
<xf:widgetpos id="thread_view_sidebar" context-thread="{$thread}" context-posts="{$posts}"  position="sidebar" />
1513964772607.webp
1513964809867.webp
 
Thank you @DL6.

I've edited this:
<xf:widgetpos id="thread_view_sidebar" context-thread="{$thread}" context-posts="{$posts}" position="sidebar" />
... but it's still not working in Thread view: Sidebar position.

My code in the widget now is:
HTML:
<xf:if is="count($posts) >2">
<div class="adSense ad_above_content" align="center" style="padding: 30px 0px; border: 1px solid #e4e4e4; border-radius: 5px; background: #3d70d2;">
<div align="center" style="color: #fff;">FMU__thread_view_sidebar</div>
</div>
</xf:if>
 
Should be
Rich (BB code):
<xf:if is="count($context.posts) > 2">
<div class="adSense ad_above_content" align="center" style="padding: 30px 0px; border: 1px solid #e4e4e4; border-radius: 5px; background: #3d70d2;">
<div align="center" style="color: #fff;">FMU__thread_view_sidebar</div>
</div>
</xf:if>

PS: Happy holidays for all who read this :)
 
Most of this isn't needed.

If you only want to show ads on a thread which has a certain number of replies, then you will just want this:
HTML:
<xf:if is="$thread.reply_count > 2">
    <!-- blah -->
</xf:if>
If you want it dependent on the number of posts on the page then you could always use __globals:
HTML:
<xf:if is="count($__globals.posts) > 2">
    <!-- blah -->
</xf:if>
 
Thank you, @Chris D , but as much as I try the problem persists.

If I add:
HTML:
<xf:if is="$thread.reply_count > 2">
    TEST
</xf:if>
... to Thread view: Sidebar widget position it will not show at all.


The same thing is for example with conditional statement:
HTML:
<xf:if is="$template == 'thread_view'">
   TEST
</xf:if>
... if I add it to any widget to show content only on thread view with a widget.
 
Most of this isn't needed.

If you only want to show ads on a thread which has a certain number of replies, then you will just want this:
HTML:
<xf:if is="$thread.reply_count > 2">
    <!-- blah -->
</xf:if>
If you want it dependent on the number of posts on the page then you could always use __globals:
HTML:
<xf:if is="count($__globals.posts) > 2">
    <!-- blah -->
</xf:if>
When used on ad location > container sidebar (above), the code does not work.
What is the proper code to use on the sidebar?
 
Back
Top Bottom