Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Вывод в опрегделенных категориях по id <meta name="robots" content="noindex,follow">


 Share

Recommended Posts

OpenCart версия 3.0.3.3

 

Подскажите пожалуйси, есть задача вывести <meta name="robots" content="noindex,follow"> в некоторых категориях.

 

Пробую посивить условие в catalog/controller/product/category

if ($this->data['category_id] == {647,456,479} {
                $this->document->setRobots( 'noindex,follow' );
 }

Но категории вообещё пересиют загружаться.

 

У меня стоит уже дорилитка чтобы на страницах пагинации в категориях, продуких, корзине и т.д. выводился <meta name="robots" content="noindex,follow">

И вот теперьь нужно еещё добавить id опрегделенных категорий.

 

Ниже код модификатора который стоит

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name>Robot noindex</name>
    <code>ox_robot_noindex</code>
    <version>2.1.1</version>
    <ocversion>3.0.2.x</ocversion>
    <author>slasoft / OSWorX</author>
    <authorEmail>[email protected]</authorEmail>
    <link>https://osworx.net</link>
    <license>GNU/GPL</license>
    <date>2018.11.13</date>
    <description>Add metat tag noindex, follow to category, information, manufacturer and some special product pages</description>

    <file path="system/library/document.php">
        <operation>
        <search>
            <![CDATA[
                private $scripts = array();
            ]]>
        </search>
        <add position="after">
            <![CDATA[
    /** + robot, noindex */
    private $robots;

    public function setRobots($value) {
        $this->robots = $value;
    }

    public function getRobots() {
        return $this->robots;
    }
            ]]>
        </add>
        </operation>
    </file>

    <file path="catalog/controller/common/header.php">
        <operation>
            <search>
                <![CDATA[
                    $data['base']
                ]]>
            </search>
            <add position="after">
                <![CDATA[
        /** + robot, noindex */
        $data['robots'] = $this->document->getRobots();
                ]]>
            </add>
        </operation>
    </file>

    <file path="catalog/controller/product/{category,manufacturer,special}.php">
        <operation>
            <search>
                <![CDATA[
                    $this->document->setTitle(
                ]]>
            </search>
            <add position="after">
                <![CDATA[
            /** + robot, noindex */
            if( isset( $this->request->get['page'] ) || isset( $this->request->get['limit'] ) || isset( $this->request->get['order'] ) ) {
                $this->document->setRobots( 'noindex,follow' );
            }
                ]]>
            </add>
        </operation>
    </file>

    <file path="catalog/controller/account/{forgotten,login,register}.php|catalog/controller/checkout/{cart,checkout}.php|catalog/controller/information/information.php|catalog/controller/product/{compare,search}.php">
        <operation>
            <search>
                <![CDATA[
                    $this->document->setTitle(
                ]]>
            </search>
            <add position="after">
                <![CDATA[
            /** + robot, noindex */
            $this->document->setRobots( 'noindex,follow' );
                ]]>
            </add>
        </operation>
    </file>

       <file path="catalog/view/theme/*/template/common/header.twig">
        <operation>
            <search>
                <![CDATA[
                    <title>
                ]]>
            </search>
            <add position="before">
                <![CDATA[
{% if robots %}
<meta name="robots" content="{{ robots }}" />
{% endif %}
                ]]>
            </add>
        </operation>
    </file>
</modification>

 

Link to comment
Share on other sites


if ($this->data['category_id] == {647,456,479} {
                $this->document->setRobots( 'noindex,follow' );
 }

 

 

if (in_array($this->data['category_id], [647,456,479]) {
                $this->document->setRobots( 'noindex,follow' );
 }

Link to comment
Share on other sites

6 часов назад, chukcha сказал:

if (in_array($this->data['category_id], [647,456,479]) {
                $this->document->setRobots( 'noindex,follow' );
 }

 

Откуда $this->data у автора?

if (in_array($this->data['category_id'], [647,456,479])) {
		$this->document->setRobots('noindex,follow');
}

или

if (isset($this->request->get['path'])) {
	$parts = explode('_', (string)$this->request->get['path']);
	$category_id = (int)array_pop($parts);
	if (in_array($category_id, [647,456,479])) {
		$this->document->setRobots('noindex,follow');
	}
 }

 

Link to comment
Share on other sites

@klest333 мне кажется, вы пошли сложным путем.

Можно ведь просто в блоке с описанием к категории прописать в исходном когде <meta name="robots" content="noindex,follow" />

Если у вас редактор не удаляет теги, то на страниэто категории соответсвенно и вывегдется данная конструкция.

image.png.26b7d1c00c215f5dbeb2a8df276f2680.png

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
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.