Important. We are closed. Due to decreased amount of time available, we don't accept new orders and we don't provide support for existing ones.

Outstanding and responsive customer support manaDEV has. Their support led me through the process of installing and configuring it, when problems show ... Read more

Jul 2, 2014 Professor62

Certified Magento Enterprise developer Certified Magento developer Certified Magento theme developer Certified Magento specialist

Manadev is certified extension and theme
developer for Magento

Examples

Contents:

General Notes

This article contains examples based on standard Magento sample data, so that you can easily try them on Magento installation containing sample data.

We understand that providing relevant content for brands is in many cases more useful than for colors. However, standard Magento sample data doesn't have brands and we think that being easy to try is more important here. In case it is easier to understand, you can substitute colors with brands in all the examples below.

Examples implement various content strategies which are explicitly defined in the beginning of the example. Please note that these strategies are designed to illustrate different techniques of composing filter-specific content, these strategies are not-necessarily the best in terms of SEO.

You can work with these examples in 2 ways:

  1. Copy template instructions to to template files in your theme subdirectory and check how it works, in case attribute code or brand names are different, edit them in template instructions as needed.
  2. Alternatively, you can just read through template instructions and if example has a link to demo, check the result in extension demo.

"Notes" section of each example often explains how template methods are used. Please read method reference for all the details.

Though variable are not used in examples, mainly for being less readable, you may consider using variables as described in variable reference.

Examples also follow recommendation from How It Works article for alternative syntax for control structures in visual content templates and using plain PHP syntax in meta content templates.

Examples also demonstrate usage of indentation, empty lines and comments to increase readability of template instructions.

Stack Color Descriptions After Category Description

Content Strategy

Color-specific description should be rendered after category description. If there are several color filters applied, description of every color should be rendered.

Demo: http://m2-demo.manadev.com/filter_specific_content/women/tops-women/jackets-women/color/blue-green-red.html

description.phtml

<?php echo $this->originalDescription() ?>

<?php if ($this->filter('color')->contains('Red')): ?>
    <p>Red-specific description</p>
<?php endif; ?>

<?php if ($this->filter('color')->contains('Green')): ?>
    <p>Green-specific description</p>
<?php endif; ?>

<?php if ($this->filter('color')->contains('Blue')): ?>
    <p>Blue-specific description</p>
<?php endif; ?>

Notes

  • originalDescription() method is used to render original category description.
  • filter()->contains() method is used to check whether color filter is applied.
  • The same technique may be used to display any content: brand banners, links, additional menus, ads, etc

Prepend Category Title (<h1>) And Meta Title With Color Name

Content Strategy

  • On category pages having exactly one color filter applied:
    • add color name before category name, so that:
      • page <h1> should be Red Bags, Green Jackets, etc
      • meta title should be Red Bags, Green Jackets, etc
    • in meta title, remove color name from list of applied filters normally displayed in the end of meta title.
  • In other cases, do nothing.

Demo:

h1_title.phtml

<?php if ($this->category() && $this->filter('color')->count() == 1): ?>
    <?php echo $this->filter('color')->first() ?>
<?php endif; ?>

<?php echo $this->originalH1Title() ?>

meta_title.phtml

if ($this->category() && $this->filter('color')->count() == 1) {
    // prepend meta title with color name and separate them with space
    echo $this->filter('color')->first(). ' ';

    // remove color filter from list of applied filters, so that it is not
    // added after default meta title with the logic in the end of this
    // template
    $this->filter('color')->exclude();
}

// show default meta title
echo $this->originalMetaTitle();

// Add labels of all applied filters and separators in between
$filterCount = $this->filters()->countIncluded();
foreach ($this->filters()->allIncluded() as $index => $filter) {
    if ($index == 0) {
        echo __(": ");
    }
    elseif ($index < $filterCount - 1) {
        echo __(", ");
    }
    else {
        echo __(" and ");
    }

    echo $filter->item_label;
}

// Add page number to page title
if ($this->page() > 1) {
    echo __(" (Page %d)", $this->page());
}

In these templates:

  • category() method is used to check that category page is being displayed
  • filter()->count() method is used to check exactly 1 color filter is applied
  • filter()->first() method is used to get name of first applied color filter
  • filter()->exclude()method is used to remove color filter in meta title template. Note that is will still be present when processing other content templates.
  • $this->filters()->countIncluded() method is used to get number of applied filters to be rendered after standard meta title (that is, those not excluded with filter()->exclude()method call).
  • $this->filters()->allIncluded() method is used to get all applied filters to be rendered after standard meta title (that is, those not excluded with filter()->exclude()method call).
  • $this->page() method is used current product list page which user can change in product list toolbar.
  • originalH1Title() method is used to render original category name.
  • originalMetaTitle() method is used to render original category meta title.
  • in meta title template everything below echo $this->originalMetaTitle() is standard logic of adding all applied filters to to meta title which comes with default meta title template.

Add Subtitle With Blue Color Slogan

Content Strategy

Add slogan below page title if blue filter is applied.

Demo: http://m2-demo.manadev.com/filter_specific_content/women/tops-women/jackets-women/color/blue.html

h2_title.phtml

<?php if ($this->filter('color')->contains('Blue')): ?>
    <h2>Blue is the new white.</h2>
<?php endif; ?>

Notes

  • filter()->contains() method is used to check whether color filter is applied.

Advise Search Engine To Index Only Certain Colors

Content Strategy

  • index pages filtered by no more than one color: Red, Green or Blue.
  • don't index any other category pages.
  • follow pages filtered by exactly one filter
  • follow pages filtered by 2 filters one of which is color Red. Green, or Blue.
  • don't follow any other filters.

Demo:

Settings

Most of content strategy requiremented can be implemented with settings in Manadev -> SEO -> Global Configuration:

  • Apply robots = NOINDEX -> If number of applied filters is equal or more than set to 1
  • Apply robots = NOFOLLOW -> If number of applied filters is equal or more than set to 2

meta_index.phtml

if ($this->filters()->are(['color' => 'Blue'])) {
    echo 'INDEX';

} elseif ($this->filters()->are(['color' => 'Green'])) {
    echo 'INDEX';

} elseif ($this->filters()->are(['color' => 'Red'])) {
    echo 'INDEX';

} else {
    // show default INDEX or NOINDEX
    echo $this->originalIndex();
}

meta_follow.phtml

if ($this->filters()->count() == 2) {
    if ($this->filter('color')->contains('Blue')) {
        echo 'FOLLOW';

    } elseif ($this->filter('color')->contains('Blue')) {
        echo 'FOLLOW';

    } elseif ($this->filter('color')->contains('Blue')) {
        echo 'FOLLOW';

    } else {
        // show default FOLLOW or NOFOLLOW
        echo $this->originalFollow();
    }

} else {
    // show default FOLLOW or NOFOLLOW
    echo $this->originalFollow();
}

Notes

  • filters()->are() method is used to check for exact filter match
  • filters()->count() method is used to check that number of applied filters is exactly 2
  • filter()->contains() method is used to check whether color filter is applied.
  • originalIndex() method is used to render original INDEX or NOINDEX, as specified in SEO configuration.
  • originalFollow() method is used to render original FOLLOW or NOFOLLOW, as specified in SEO configuration.

Provide Custom Descriptions For Exact Filter Combinations In Certain Categories And Only On First Page

Content Strategy

  • Provide unique and relevant descriptions for certain combination of color and style filters in Jacket categories (both men and women)
  • Handle both Men Jackets category and Women Jackets category
  • Check only exact matches. If there are more filters, don't apply these descriptions
  • In other cases, use default descriptions.
  • Provide description only on the first page (be it custom or default description). On all subsequent pages, show no description.

Demo:

description.phtml

<?php $continue = false; // introduce custom variable ?>

<?php if ($page < 2): // first page of products ?>
    <?php if ($this->category() == 14): // men jackets category ?>
        <?php if ($this->filters()->are(['color' => 'Red', 'style_general' => 'Insulated'])): ?>
            <p>Description specific to red insulated men jackets</p>

        <?php elseif ($this->filters()->are(['color' => 'Red', 'style_general' => 'Hooded'])): ?>
            <p>Description specific to red hooded men jackets</p>

            <?php // add more men jacket descriptions here ?>

        <?php else: ?>
            <?php $continue = true; // no unique description provided - render default one ?>
        <?php endif; ?>

    <?php elseif ($this->category() == 23): // women jackets category ?>
        <?php if ($this->filters()->are(['color' => 'Red', 'style_general' => 'Insulated'])): ?>
            <p>Description specific to red insulated women jackets</p>

        <?php elseif ($this->filters()->are(['color' => 'Red', 'style_general' => 'Hooded'])): ?>
            <p>Description specific to red hooded women jackets</p>

            <?php // add more women jacket descriptions here ?>

        <?php else: ?>
            <?php $continue = true; // no unique description provided - render default one ?>
        <?php endif; ?>

    <?php else: ?>
        <?php $continue = true; // no unique description provided - render default one ?>
    <?php endif; ?>


    <?php if ($continue): // if no unique description provided ?>
        <?php echo $this->originalDescription() ?>
    <?php endif; ?>

<?php endif; ?>

Notes

  • category() method is used to check if specific category page is being rendered. Comparison is made by category ID.
  • filters->are() method is used to check for exact match of all applied filters.
  • $continue custom variable is introduced to keep track is custom description have been rendered or not. Later this variable is used to render default description if custom description have not been rendered.
  • default meta description logic uses __() function to translate text to store's language.
  • $page variable is used to check if first page of product list is being rendered.

We Accept: PayPal Visa MasterCard American Express Discover