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 626 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
Day of Week Condition in Bricks

Day of Week Condition in Bricks

Displaying elements conditionally based on the current day of the week.
Categories:
Pro
Checking ‘PublishPress Future’ plugin’s Future Action enabled posts

Checking ‘PublishPress Future’ plugin’s Future Action enabled posts

PublishPress Future is a handy plugin for scheduling actions like unpublishing or deleting posts (of any post type) at a specified date and time in…
Categories:
Pro
City-based and Country-based Conditional Output in Bricks

City-based and Country-based Conditional Output in Bricks

This Pro tutorial provides the steps to render a Bricks element only if the visitor is from the specified country or city. Note: Caching may…
Categories:
Pro
Conditional Rendering Based On Meta Box Group’s Sub Field

Conditional Rendering Based On Meta Box Group’s Sub Field

This Pro tutorial shows how we can output an element on a single post pages only if a specified sub-field (custom field created using Meta…
Pro
Conditional Output in Bricks based on if Content has Headings

Conditional Output in Bricks based on if Content has Headings

How to prevent the output of the table of contents if the content has no headings.
Categories:
Tags:
Conditionally Outputting Based on Query Count in Bricks

Conditionally Outputting Based on Query Count in Bricks

Update on 22 Sep 2023: There's a much simpler built-in method now. See this post. In the Bricks Facebook group a user asks: Is there…
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
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: