Jump to content
dvir

add page number to meta title in category page

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 ?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

hi,

 

thanks for the reply - but still, i cant see any number on the meta title .

 

i tried to look at category meta title and on sub - category - nothing..

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

YES - it's the same. this is why is so weird. maybe i'm not getting to the meta file, because some module i have ?

 

i think i have seo module that I've bought , but how can i know what is the reason ? 

Share this post


Link to post
Share on other sites

You can try going to the Advanced Parameters > Performance tab and changing "Disable non PrestaShop modules" and "Disable all overrides" to "Yes". If the page number appears, then it's a module or override.

Share this post


Link to post
Share on other sites

i did it - but still nothing . 

i've disabled all the non- prestashop module + disable all overrides.

 and i'm still not getting any page number on the meta title

Share this post


Link to post
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'),

Share this post


Link to post
Share on other sites

I'm interested too.

I need to do this on PS1.7.4.2. Any help?

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

I tried using {$smarty.get.p} on PS1.7 but unfortunatelly it doesn't works.

Share this post


Link to post
Share on other sites

I think it's changed to {$smarty.get.page} in PrestaShop v1.7.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More