Add-ons Items This Page 1.1.1

CR LEAKS

CR LEAKS

Administrative
Joined
Mar 25, 2022
Messages
1,272
Reaction score
5,190
Points
113
Credits
19,596
Adds a new template variable $xf.itemsThisPage containing how many posts/media items/resources/etc. are shown on a page.

This is useful in templates if you want to adjust the display of some element based on how many posts or threads or media items there are displayed.

For example, you might want to hide an element from the sidebar on short threads (or on the last page of a thread where only one or two posts are shown), to prevent the sidebar from being much longer than the content.

Usage example:

The following code might be used in a sidebar ad placement to hide the advert on short thread pages.

HTML:
Please, Log in or Register to view codes content!


An even easier way

If we combine this addon with the Template Parent addon, which gives us a shorthand way of referencing all of the various thread and forum types in template names using a new $xf.reply.templateParent template variable - we can simplify the above example even further:

HTML:
Please, Log in or Register to view codes content!


Hiding ads when there is no content

I use the following code on PropertyChat to hide adverts when there is no content on the page:

HTML:
Please, Log in or Register to view codes content!

... we can do this even on PAGE_CONTAINER level adverts because if $xf.itemsThisPage is not defined it will simply return null ... so by using $xf.itemsThisPage === 0 we can say "if it is defined and is actually equal to zero, then do this" ... while still doing something else on pages where it hasn't been defined and thus returns null.


Content locked
This content has been locked. You can unlock it with 8 credits.
 
4,479Threads
10,387Messages
39,585Members
CodeinLatest member
Top