Jump to content

add page number to meta title in category page


dvir

Recommended Posts

hi,

 

i have category pages with a lot of products. 

for example : 

https://www.cdsoft.co.il/index.php?id_category=7&controller=category&id_lang=3&p=4

https://www.cdsoft.co.il/index.php?id_category=7&controller=category&id_lang=3&p=3

https://www.cdsoft.co.il/index.php?id_category=7&controller=category&id_lang=3&p=2

 

they all have the same meta title .

 

i want to add to each meta title " page number XX"

 

HOW TO DO IT ?

Link to comment
Share on other sites

Try creating override/classes/Meta.php with the following:

<?php

class Meta extends MetaCore
{
    public static function getCategoryMetas($id_category, $id_lang, $page_name, $title = '')
    {
        $metas = MetaCore::getCategoryMetas($id_category, $id_lang, $page_name, $title);
        
        if ((int)Tools::getValue('p') > 1) {
            $metas['meta_title'] .= ' (page '.(int)Tools::getValue('p').')';
        }
        
        return $metas;
    }
}

This should add the page number in brackets to the meta-title if there is more than one page. The first page will not have any page number.

 

Remember to go to Advanced Parameters > Performance and then click the "Clear cache" button (or manually delete cache/class_index.php) so PrestaShop can find the override.

Link to comment
Share on other sites

Seems this is harder than I thought it would be. Strangely, when I check my PrestaShop v1.6.1.6 test site, it is already adding the page number to the meta-title. I see Women on the first page and Women (2) on the second page. I'm not sure why your PrestaShop isn't already doing this.

Link to comment
Share on other sites

Here's what my Meta::getCategoryMetas function looks like from classes/Meta.php:

    public static function getCategoryMetas($id_category, $id_lang, $page_name, $title = '')
    {
        if (!empty($title)) {
            $title = ' - '.$title;
        }
        $page_number = (int)Tools::getValue('p');
        $sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
				FROM `'._DB_PREFIX_.'category_lang` cl
				WHERE cl.`id_lang` = '.(int)$id_lang.'
					AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl');

        $cache_id = 'Meta::getCategoryMetas'.(int)$id_category.'-'.(int)$id_lang;
        if (!Cache::isStored($cache_id)) {
            if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) {
                if (empty($row['meta_description'])) {
                    $row['meta_description'] = strip_tags($row['description']);
                }

                // Paginate title
                if (!empty($row['meta_title'])) {
                    $row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
                } else {
                    $row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
                }

                if (!empty($title)) {
                    $row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
                }

                $result = Meta::completeMetaTags($row, $row['name']);
            } else {
                $result = Meta::getHomeMetas($id_lang, $page_name);
            }
            Cache::store($cache_id, $result);
            return $result;
        }
        return Cache::retrieve($cache_id);
    }

As you can see, it's already adding the page number to the meta-title. Does your function have this code?

Link to comment
Share on other sites

hi - I've found it :)  

 

i'm using blocklayered module , and there is a function call Ajax call.

when i'm using blocklayered- the meta title comes from the ajax function :)

 

so - with the help of Yaniv Mirel  -  in line 3174 , on module/blocklayered/blocklayered.php - line 3174 :

 

'meta_title' => $meta_title . ' | ' . $this->l('page') . ' ' . $p .  ' - ' . Configuration::get('PS_SHOP_NAME'),

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...
  • 3 months later...

In prestashop 1.6 i just add the folowing to add the page number to the title or any other meta info, just add it to the header.tpl using the smarty ability to get page ({$smarty.get.p})

i.e.

<title>{$meta_title|escape:'html':'UTF-8'|truncate:120:"":false}{if isset($smarty.get.p) && $smarty.get.p} ({$smarty.get.p}){/if}</title>

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...
  • 11 months later...
  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...