19th Jul '24
/
4 comments

Conditional Output on the First Page of Archives in Bricks

A user asks:

if i have wg. category page with list of items – i have 3 pages. i want to show some text only on first page.

its possible to make it?

We can check the value of get_query_var( 'paged' ) in a dynamic data condition to output an element only on the first page of paginated archives in Bricks.

For example,

example.com/category/nature/:

example.com/category/nature/page/2:

Step 1

Whitelist the get_query_var function.

Ex.:

<?php 

add_filter( 'bricks/code/echo_function_names', function() {
  return [
    'get_query_var'
  ];
} );

You should also add other functions (native or custom) being used in your Bricks instance besides get_query_var. This can be checked at Bricks → Settings → Custom code by clicking the Code review button.

More info on whitelisting can be found here.

Step 2

Edit your archive template with Bricks.

Apply a dynamic data condition on the element that you wish to be output only on the first page like this:

{echo:get_query_var(paged)}

Get access to all 612 Bricks code tutorials with BricksLabs Pro

4 comments

  • It's work great for blog, but not working for WooCommerce categories, any help?

    • A

      Are you using the Products element or a query loop?

      • Hello Sridhar, I using Query loop I tried to filter using 'is_shop', is_product_category' also tried 'page' not 'paged' but it not helped me ))

  • Michał Czajka

    works great for me. this is what i need.

Leave your comment

 

Related Tutorials..

Pro
Conditionally Rendering an Element Outside the Loop based on Taxonomy Term in Bricks

Conditionally Rendering an Element Outside the Loop based on Taxonomy Term in Bricks

A user asks: Hiding element based on taxonomy I have an element in a footer that I want to hide if a page has a…
Categories:
Pro
User Role Conditional Output in Bricks

User Role Conditional Output in Bricks

This Pro tutorial provides the steps to output elements based on their CSS class to users of the specified role in WordPress when using Bricks…
Categories:
Pro
ACF Repeater sub field value dynamic data condition in Bricks

ACF Repeater sub field value dynamic data condition in Bricks

This Pro tutorial provides the steps to output an element on single posts (can be of any post type) only if a specified ACF (Pro)…
Pro
Checking if the current Page/Post has Children i.e. is a Parent in Bricks

Checking if the current Page/Post has Children i.e. is a Parent in Bricks

Shows how we can check whether the current Page or Post (of any hierarchical post type) is a parent
Categories:
Pro
Condition for checking Bricks content

Condition for checking Bricks content

Only outputting Bricks content when a Page is built with Bricks, otherwise display WP content.
Categories:
Weekday Condition in Bricks

Weekday Condition in Bricks

As of Bricks 1.7, the built-in "Weekday" condition does not work correctly. This is most likely due to it not taking the site's timezone (set…
Categories:
Condition for Checking Current Post Category in Bricks

Condition for Checking Current Post Category in Bricks

How we conditionally display an element based on the current post's categories.
Categories:
[Function] Current Term Has Children

[Function] Current Term Has Children

Updated on 20 Jul 2024 A user asks: I'm working on an archive template for WooCommerce products. I'm trying to hide a section if there…