GB pagination condition

  • Hi

    I am trying to create a GB condition for the second and subsequent pages of an archive.

    I have a content template for the archive which includes a container with some description elements, then a query block that inherits from the template query. All I want to do is only show the description container on the first archive page.

    I have tried – unsuccessfully – to create a query parameter condition.

    Your guidance?

  • Hi there,

    You can do this with a CSS class on the description container.

    Select that container and add archive-intro under Advanced > Additional CSS class(es). Then add this CSS:

    
    body.paged .archive-intro {
    	display: none;
    }
    

    WordPress adds the paged body class on page 2 and subsequent pages, so the description will remain visible only on the first page.

    The Query Parameter condition won’t detect pagination URLs like /page/2/, because the page number isn’t a query string parameter.

    This approach hides the description visually, though it remains in the page’s HTML.

  • Thanks Alvind

    Your solution works, but I didn’t want to send the HTML for the description. It contains image links and could be quite heavy.

    I rethought the problem and changed my approach. I made the archive description a separate element, added by a hook element to all archives using the exclude “paginated results” in the display rules.

    You might think about aligning display rules and conditions for future releases?

    appreciate the relevant and timely response.

    keith

  • That’s a clever solution 🙂

    By the way, the Conditions system is extendable, which means you can code your own custom conditions if the default ones don’t provide what you need.

    Here’s the documentation if you’d like to explore it further:

    https://learn.generatepress.com/developer-doc/conditions/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.