Jump to content

category page title name


androidstore

Recommended Posts

Hello I've been searching for 2 hours but I couldnt find any solution to this problem:

 

When I go to next page in category then title name stays same - its ok - but next to the title name is number of current page in parentheses.

 

It looks like this:

 

default page title name = "Mobile devices"

page 2 title name = "Mobile devices (2)"

page 3 title name "Mobile devices (3)" and so on..

 

This way it looks like (2) or (3) undread messages or so..

 

How do I get rid of this paging in title name? Or can I atleast somewhere rename title to "Mobile devices - page 2" ?

 

Thanks for any help!

 

Regards,

 

Michal

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...


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');

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');

 

return Meta::completeMetaTags($row, $row['name']);

}

 

return Meta::getHomeMetas($id_lang, $page_name);

}

Link to comment
Share on other sites

Will this work or how should it look?

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

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


 

Link to comment
Share on other sites

sorry, i missed your reply here

 

use this: 

(!empty($page_number) ? : '':'')
this is shorthand if :)

 

So you make a if for having the same result whatever the result of your condition is ? Not very good.

Better removing this shorthand if and just let this (same result, better code) :

 

If you want to remove page number in the title (which is not really recommended for SEO reasons and for your users) :

 

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

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

 

If you want to have a "- page N -" in your <title>, use :

 

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

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

This last code block answer the androidstore question and is based on the getCategoryMetas function submited above.

Please test this code before using it on a production environment. And of course overload the original class, don't edit the Prestashop Core.

 

Hope this helps anyone,

Best regard,

Ciseur

Edited by Ciseur (see edit history)
Link to comment
Share on other sites

Thanks for both of your replies. I don't think most users find "iPads (2), iPads (12)" etc, very clear. It doesn't indicate that it's the current page you're on. A problem I came to think of if you're gonna add text to the title is multi-language. Can you make the title multilingual?

Link to comment
Share on other sites

If you want to translate the "page" string to localize your <title>, use $this->l() function

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

if (!empty($title))
	$row['meta_title'] = $title.(!empty($page_number) ? ' - '.$this->l('page').' '.$page_number : '').' - '.Configuration::get('PS_SHOP_NAME');
Hope, it's clear and it helps.

Best regards,

Ciseur

Link to comment
Share on other sites

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...