shopp('collection.has-faceted-menu')

Tests if the current category has faceted menus enabled.

shopp('collection', 'has-faceted-menu', 'options')

@param string $object the object or object.tag combination, if object.tag is used, the tag parameter can be omitted
@param string $tag the tag, can be hyphenated or not. Prefix with 'get' as shorthand for the return=true option
@param mixed $options associative array, or url-style name=value pairs separated by ampersands (&). Each pair is passed to the theme api tag as an option.
@returns boolean true if the current product category has faceted menu options, else false.

Alternative Forms

shopp('collection.has-faceted-menu', 'options');

Description

Tests if the current category has faceted menus enabled.

If this theme API function returns true, faceted menu options are loaded, and can be displayed using shopp('collection','faceted-menu') or can be looped through using shopp('collection','facet-options').

Note: Be careful to only use this function on product category collections. This function may result in a Fatal Error if executed on another product collection type.

To protect against this, check to make sure the global collection object is of type ProductCategory.

Safe, checking ProductCategory type

if ( is_a(ShoppCollection(), 'ProductCategory') && shopp('collection.has-faceted-menu') ) {}

Safe, category is loaded programmatically, so you know the it’s a category.

// loading category with id=5
shopp('storefront.category','id=5&load');
if ( shopp('collection.has-faceted-menu') ) {}

Universal Options

All Theme API calls have these options.

  • return: when set to true, 1, or on, this option forces the tag to return the value instead of displaying/echoing the value to the page. Alternatively, prefix the tag parameter with get to get the same effect. All theme api tags that return a boolean value will return by default.
  • echo: when set to false, 0, or off, this option forces the tag to display the value to the page. This is the default for all non-boolean tags.
  • is: when set to true, 1, or on, this option will evaluate the return of the theme api call as a boolean true or false value. See how values are converted to boolean.

Options

None

Examples

<?php if ( is_a(ShoppCollection(), 'ProductCategory') && shopp('collection.has-faceted-menu') ) { … } ?>
<?php if ( is_a(ShoppCollection(), 'ProductCategory') && shopp('collection.has-faceted-menu') ): ?>
…content displayed if the category has faceted menus enabled…
<?php endif; ?>

Display pre-fab faceted menu

if ( is_a(ShoppCollection(), 'ProductCategory') && shopp('collection.has-faceted-menu') ):
    shopp('collection.faceted-menu');
endif;

Loop through facet options

<?php if ( is_a(ShoppCollection(), 'ProductCategory') && shopp('collection.has-faceted-menu') ): ?>
    <?php while ( shopp('collection.facet-options') ): ?>
    …facet menu options content here
    <?php endwhile; ?>
<?php endif; ?>

Similar to shopp('collection','faceted-menu'), appropriate for a facetedmenu.php content template.

<?php
// a custom product category with faceted menu feature enabled
if ( is_a(ShoppCollection(),'ProductCategory') && shopp('collection.has-faceted-menu') ) :

// List current filters
if (shopp('collection.is-facet-filtered')) : ?>


<ul>
    <?php // Loop through toggled filters for this category
    while(shopp('collection.facet-filters')) : ?>
    <li>
        <strong><?php
        // facet menu name of toggled filter
        shopp('collection.facet-name'); ?>:</strong>&nbsp;<?php
        // current toggled facet filtered value
        shopp('collection.facet-filter'); ?>
        <a href="<?php
        // current toggled facet toggle link url
        esc_url(shopp('collection.facet-link')); ?>" class="cancel">X</a>
    </li>
    <?php endwhile; ?>
</ul>

<br />
<?php endif; ?>



<ul class="faceted-menu">
    <?php
        // Loop through faceted menus
        while(shopp('collection.facet-menus')) :

        // Skip active filters and menus with no options
        if ( shopp('collection.facet-filtered') ) continue;
        if ( ! shopp('collection.facet-menu-has-options')) continue;
    ?>
    <li>
        <h4><?php
        // current facet filter name
        shopp('collection.facet-name'); ?></h4>
        <ul class="facet-option <?php
            // current facet filter slug
            shopp('collection.facet-slug'); ?>">
            <?php
            // Loop through filter options for this faceted menu
            while(shopp('collection.facet-options')) : ?>
                <li>
                    <a href="<?php
                        // toggle url for current filter option
                        esc_url(shopp('collection.facet-option-link')); ?>"><?php
                        // the full label of the facet filter option
                        shopp('collection.facet-option-label'); ?></a>&nbsp;
                    <span class="count"><?php
                    // the number of products sharing this facet
                    shopp('collection.facet-option-count'); ?></span>
                </li>
            <?php endwhile; ?>
        </ul>
    </li>
    <?php endwhile; ?>
</ul>


<?php endif; ?>

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar