How to hide elements on pagination pages in MODX Revolution

By Oleg Tolochko, published on 2023-10-22
How to hide elements on pagination pages in MODX Revolution

I decided to note it for the future. Actually the question of hiding some elements, text or section on pagination pages - this is one of the basic points of technical optimization of the site.

Then search engines crawl your site, they must add the first page of pagination in the index. For this reason, the text should only be on it. If you show the text on all pages, the main page can be defined as a double, and "thrown" out of the index or lowered in ranking. We don't need that.

My question was how to get the page number from the URL parameters in MODX. You can write a snippet, but there must be faster options, right? There should be and there are.

So, since pagination is most often implemented via the pdoPage snippet of the pdoTools package, you can use the playshoder installed by this snippet:

[[+page:isgte=`2`:then=``:else=`
    [[*content]]
`]]

If the page is greater than or equal to 2, it outputs nothing. Otherwise, it outputs content field, or whatever you want - you can put HTML layout there, and everything else.

Also an interesting variant - the same thing, but page get not as placeholder from snippet, but as placeholder from GET parameters. It turns out that pdoTools adds a syntax for getting URL parameters - an interesting feature I didn't know about.

[[!#get.page]]

The syntax of the condition will be the same as in the first example.

For those who work with Fenom - output will also be via a condition with GET parameters. For example (most likely you can write just if with negation of the condition, but now there is no time to test it):

{if $.get['page']}
{else}
    {$_modx->resource.content}
{/if}
Written by Oleg Tolochko
Owner, author and editor of the ITWebMind.com

Since 2021 I have been working on freelancing, mainly in the field of advertising, development and promotion of websites. I am interested in programming, in particular Python, PHP, JS to a greater extent for myself and automation of my projects. Also design, SEO, context and targeted advertising, productivity, various areas of management. I am fond of playing guitar, horses, snorkeling. Traveling in Asia at the moment. In this blog I collect my work experience for myself and others, as well as improve my skills in design, website development and promotion, copywriting.

Please rate this article
(4.7 stars / 3 votes)