Saturday , February 22 2025

Title for bitrix pagination

I will not describe why this is necessary, I will only publish a ready-made solution.

else echo $APPLICATION->ShowProperty("meta_title");
if (isset($_GET['PAGEN_1']) && $_GET['PAGEN_1']!=1) { echo " Page ".$_GET['PAGEN_1']; }
if (isset($_GET['PAGEN_2']) && $_GET['PAGEN_2']!=1) { echo " Page ".$_GET['PAGEN_2']; }
if (isset($_GET['PAGEN_3']) && $_GET['PAGEN_3']!=1) { echo " Page ".$_GET['PAGEN_3']; }

The disadvantage of this condition is that the listing is manual, and if you have 100 pages of pagination, this copy-paste will not be very comfortable. But in Bitrix there is no comfort at all.

A detailed version from some project with which I worked for the SEO customization:

if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=2+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 2';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=3+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 3';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=4+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 4';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=5+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 5';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=6+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 6';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=7+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 7';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=8+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 8';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=9+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 9';
}
else if(preg_match ('/catalog\/(.*)\/\?PAGEN_1=10+/i', $_SERVER['REQUEST_URI'])) {
echo $APPLICATION->ShowTitle(); echo ' - page № 10';
}

else $APPLICATION->ShowTitle();

The same manual copy-paste is used here, but it is more clearly described.

Here is a way to automatically display the page number in the title:

$APPLICATION->ShowTitle(true); echo (preg_match('{.*?\?PAGEN_\d=(\d+)}', $_SERVER['REQUEST_URI'], $m) ? " – page ".$m[1] : '');

I draw your attention – this code needs to be tested, I do not remember where I used it.

Here is the detailed and quite beautiful code, with an additional condition for the news title:

<?

$t_add = (preg_match('{.*?\?PAGEN_\d=(\d+)}', $_SERVER['REQUEST_URI'], $m) ? " – page ".$m[1] : '');
$m_title = $APPLICATION->GetPageProperty('title');
if(!empty($m_title)){
	echo '<title>'.$m_title.$t_add.'</title>';
}else{
?>
	<title><?$APPLICATION->ShowTitle(); echo $t_add; ?> <?if (preg_match('#/news/\w#siU', $_SERVER['REQUEST_URI'])) echo " | News articles ";?> </title>
<?}?>

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

301 redirect in .htaccess from uppercase to lowercase characters

In web development, managing URL consistency is crucial for SEO and user experience. One common …

Leave a Reply

Your email address will not be published. Required fields are marked *