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 a Reply to Sridhar Katakam (Cancel Reply)

 

Related Tutorials..

Create A Customizable AJAX Add To Cart Button In Bricks Builder

Create A Customizable AJAX Add To Cart Button In Bricks Builder

In Bricks, you can simply create an Add To Cart button from a dynamic data / function {woo_add_to_cart}. This button supports AJAX as well if…
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
User Role Condition in Bricks

User Role Condition in Bricks

This Pro tutorial provides the steps to conditionally output elements depending on the currently logged-in user's role. Step 1 Create a section Template having the…
Categories:
Check if a given category has at least one post

Check if a given category has at least one post

There could be situations where you want to check if a given category (by its slug) has at least 1 post assigned to that category.…
Categories:
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
Check If The Latest Post Was Published in The Last X Minutes

Check If The Latest Post Was Published in The Last X Minutes

In this Pro tutorial we shall define a custom function that takes in the number of minutes as an argument and returns true if there…
Categories: