How to use custom fields as virtual categories

From JReviews Documentation
Jump to: navigation, search

One of the biggest limitations of Joomla's category system is that it doesn't allow you to add a single article/listing to more than one category. Other limitation is that all categories must be setup before you submit articles/listings.

Let's say you want to create a site with restaurants. You might want to create "Restaurants" as the main category and cuisines as subcategories, i.e "American Cuisine", "French Cuisine", "Italian Cuisine", ... But since some restaurants serve more than one cuisine, this solution is not good because Joomla will not allow you to put the same restaurant to more than one cuisine category.

We recommend to create a single "Restaurant" category without subcategories and use a JReviews custom field to create "virtual" cuisine categories.

If you want the ability to put a listing to more than one "virtual" category, create a Multiple select list or Checkboxes type of custom field, otherwise you can also use Single select or Radiobuttons field types.

Creating a custom field required for virtual categories

Go to the JReviews Fields Manager and create a custom field in a field group that belongs to your Restaurants listing type.

Virtual-categories.png

After you save the field, click the Field Options button to add the values ("virtual" categories):

Virtual-categories2.png

Assigning virtual categories to listings

If you created a Multiple select custom field, you will see something like this on the listing submit form:

Virtual-categories3.png

By holding the CTRL key (CMD on Mac), you can select more than one cuisine. To add a new cuisine, click the Add button.

If you enabled the Use Auto Complete UI option for this field, it would look like this:

Virtual-categories4.png

If you created a Checkboxes custom field instead of a multiple select, it would look like this:

Virtual-categories5.png

Advantage of checkboxes is that users can easily see all options and quickly pick the ones they want. Disadvantage is that it is not possible to add more options on the listing submit form, all of them must be created in the administration area.

Displaying virtual categories on the site

The main question you might have is how to display those "virtual" cuisine categories when someone visits the Restaurants category on your site. We recommend to use the Fields Module for this (it is automatically installed).

Find the Fields Module in Joomla Module Manager and enter the name of the custom field that you created for virtual categories into the module parameters:

Virtual-categories6.png

After you configure the module parameters, publish the module to one of the module positions provided by your Joomla template and assign it to the JReviews category page.

The module provides several different layouts for displaying the field options ("virtual" categories):

Links horizontal

Virtual-categories7.png

Links vertical

Virtual-categories8.png

Tags

Virtual-categories9.png

Dropdown list

Virtual-categories10.png


When someone chooses an option in the Fields Module, they will get to the page with a list of all listings that belong to that "virtual" category, the same as if it was a regular Joomla category.

Displaying related virtual categories

If you setup Related Custom Fields where field options of one field are controlled by field options of other field, the Fields Module will first display field options of the "parent" field and then related field options of the "child" field.

This is most useful for Country/State/City fields, you can use a single Fields Module for visitors to be able to filter listings in a Joomla category by the location fields:

Virtual-categories-related1.png

If visitors click on "California" for example, they will get California cities on the next page:

Virtual-categories-related2.png

To have this functionality, you only need to enter the name of the parent field in the parameters of the Fields Module and enable drill-down mode in the module settings.


To display this module below the Category page title, you can use the jr-listpage-below-pagetitle custom module position.

Adding custom titles and meta tags for virtual categories

By default, those virtual category pages will not have a page title or description/keywords meta tags. To set those, go to the Field SEO Manager in JReviews administration:

Virtual-categories11.png

It is recommended to use the {fieldvalue} tag for the Meta Title which represents the chosen "virtual" category and set the Show page title at the top of the list option to Yes to output the title on those pages.

Alternative solution for displaying virtual categories

Even though we recommend using the Fields Module which automatically displays all virtual categories of a field that you setup, it is possible to instead create a separate menu item for each virtual category using the Custom list type of JReviews menu item.

For example, to create a menu item that will show "french cuisine" restaurants, choose "List pages" as the main type of JReviews menu item and in menu parameters select Custom list and enter this into the Custom WHERE parameter:

Field.jr_cuisine LIKE '%*french*%'


Virtual-categories12.png

More info about Custom WHERE parameter is available in this article: Using Custom WHERE and Custom ORDER BY parameters.