Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

52. The user activated

Code:
<xf:if is="{$xf.visitor.user_state} == 'valid'">
Show content...
</xf:if>

This does also include guests! If you want to just show content to logged in users with user state valid, then you have to ask for user_id too:

Code:
<xf:if is="{$xf.visitor.user_id} && {$xf.visitor.user_state} == 'valid'">
Show content...
</xf:if>
 
There is anyway to hide a widget for bot/crawlers like Google using Conditionals Statements?

Google is crawling some of my widgets that i don't want to show to then.
 
Use a conditional to hide it from Guests.

Edit the widget and find Display condition:

Add this in the text box there: $xf.visitor.user_id

Only logged in members will see it.

That's the problem of XenForo to not separate guests from bots in Groups.

This specific widget is great to show in real time the activity in the Forum for the Guets: Live Forum Statistics.

But my problem is that widget is crawled by Google Bots and are now showing great on the results, since is just a mixed content widget.

If i hide from the visitors, my visitors wont be seeing this great widget.

:(
 
If Guests can see it, so can search bots. That isn't a Xenforo issue. That's just the way search bots work: They will crawl and index anything that is visible to anonymous visitors and doesn't require them to log in.
 
might be worth mentioning here and maybe not accurate now. google at one point of time really disliked getting served content modified for its spiders. i cannot seem to find anything on this right now.

google at one point also had some markup that could be used to enclose content that was not relevant content but i think that was for adsense spiders and not search spiders. it is just so hard to locate these old blog posts!
 
might be worth mentioning here and maybe not accurate now. google at one point of time really disliked getting served content modified for its spiders. i cannot seem to find anything on this right now.

In this case though, it's the opposite - hiding content from spiders and showing it to guests.
 
But my problem is that widget is crawled by Google Bots and are now showing great on the results, since is just a mixed content widget.

I don't understand. Is it because the widget shows up in the google results? If it's an order on the page thing, you could move it under the fold and position it with CSS to where it should be. At least that way it won't be the first text that google crawls/shows.
 
I don't understand. Is it because the widget shows up in the google results? If it's an order on the page thing, you could move it under the fold and position it with CSS to where it should be. At least that way it won't be the first text that google crawls/shows.

Between you (and admins in general) and me, Google don't offer to much support for web boards platforms. Is more a Wordpress like approach. Was a mess to separate user content from actual news (Using the great and legendary Bob's AMS for my postings).

If you see my site (link), the first thing that pops up is a very nice widget from @021, called Live Forum Statistics. Is a great way to show the forum alive in real time, i can recommend to anyone and the support from the developer is awesome.

So, the problem is: My site is listed as a media/publisher in Google, i work as a news aggregator and this widget show real time news from any website that i want using the RSS Crawler.

If you go to my Google Publisher Page or access it, some posts inside this widget show as "Ignore Thread XYZ". The Ignore function is available in the widget for anyone who doesn't want to see some thread in the real time widget.

As you can see, the Google catches this function (or the widget) as a "news thread" but i don't want Google crawling this widget, just the normal threads and forum stuff.

If the reader click on this link in the Google System, "Ignore Thread XYZ", the next thing that the reader will see is the Ignore Function confirmation and not the thread by himself.

That's my problem.

But i already talked to @021 and he is going to give me a template modification to forbidden Google to see his add-on. Again, the support from him is amazing and i really recommend the investment.
 
Look how great the Google Publisher works for our Forums. I just wanted that i have some more control of it:

 
Look how great the Google Publisher works for our Forums. I just wanted that i have some more control of it:


If this is because you don't want the ignore links appear in Google News, I think the easy solution for this would be to simply robots.txt block the urls.

Code:
Disallow: */ignore-in-lfs$
 
If this is because you don't want the ignore links appear in Google News, I think the easy solution for this would be to simply robots.txt block the urls.

Code:
Disallow: */ignore-in-lfs$

Can you make this code to ignore all the widget? Robots.txt is a great option too.

Btw, thanks for your great attention on this.
 
Can you make this code to ignore all the widget? Robots.txt is a great option too.

Btw, thanks for your great attention on this.

Not exactly. Again, it depends on what you are trying to accomplish. You only pointed to the ignore links in Google News. I believe this will solve that problem. If you have another problem, it might require a different solution.
 
need to merge two condition... if the visitor is part of x usergroups OR the thread page is from x nodes.

<xf:if is="{{$xf.visitor.isMemberOf([1,2])}}"> and <xf:if is="in_array({$__globals.forum.node_id}, [1,2])"> . these seem to work fine individually. struggling to get them to work together with OR.
 
Last edited:
You combine two conditionals with OR using: <xf:if is="$xf.visitor.isMemberOf([2,12]) || !in_array($__globals.forum.node_id, [2,13])">

With AND it's: <xf:if is="$xf.visitor.isMemberOf([2,12]) && !in_array($__globals.forum.node_id, [2,13])">
 
i am placing this code in page_container... seems to work. would test more. seems to work without __globals. really should read about the purpose of it and where it can be ignored... thanks!
 
Top Bottom