Build useful city and category landing pages
- Thread started
- Last updated
What you’ll achieve
Create city guides and filtered business lists, then keep city navigation and content beside individual listings.
My site
Create pages such as Hotels in Chicago and Restaurants in Chicago by combining business categories with city and state filters.
Organize business types and locations
Use JReviews categories to organize businesses by type, such as Hotels, Restaurants, Coffee Shops, and Bars. Keep the same business categories across all cities. Associate each category with its intended business listing type in JReviews. For the examples, Hotels uses the Hotel listing type, Restaurants uses Restaurant, and Coffee Shops and Bars use Food and drink.
Before searching, create the source fields:
- In Setup → Field Groups Manager, create a listing field group named Business location, or reuse an existing listing group.
- In Setup → Custom Fields Manager, create the listing fields City (
jr_city) and State (jr_state), both with type Select. Select Business location as each field's Field Group. - In Setup → Listing Types Manager, associate Business location with Hotel, Restaurant, and Food and drink, and any other business listing type you include in these lists.
- Add predefined options to City with these label/value pairs: Chicago /
chicago, Springfield /springfield, and Small Town /small-town. Add Illinois /illinoisto State. Visitors see the labels. Queries and the banner read the saved values. - Keep both fields active and required, writable by business submitters, and publicly readable and searchable. Enable their search display in Custom Fields Manager. Leave field and group dependencies empty for this example. If you use PaidListings, include them in the applicable plans.
The submitter chooses one city and one state on each business listing. Enter Chicago and Illinois on a published Lakefront Hotel listing. Enter Springfield and Illinois on a second hotel. These are the positive and negative checks for the first city search.
For the combined Small Town example, publish one restaurant, one coffee shop, and one bar with Small Town and Illinois. Also keep a museum in Small Town and a restaurant in Springfield to check exclusions. Give their listing types the same location field group when needed.
Create or retain a published Advanced Search page before the first search. JReviews uses that page to open search results.
Create a JReviews → Advanced Search menu item in Joomla and publish it.
Create a WordPress page, select Advanced Search in its JReviews Menu System, and publish it.
Open Advanced Search and confirm that selecting the business listing type shows City and State.
Each Custom List combines one business category with city and state filters. Reuse the same categories to create lists for other cities.
Create a Chicago guide as a published Joomla article with a menu item. Create a Chicago offers article with its own menu item for your maintained local offers.
Create published WordPress pages for the Chicago guide and Chicago offers. Add your maintained local offers to the offers page.
Give the guide the URL /chicago and the offers page /chicago/offers, or record their actual published URLs to substitute in the banner. Add links to Hotels in Chicago and Restaurants in Chicago after creating those lists below. Give each list its own useful introduction, title, and navigation back to the city guide. You do not need to recreate listing types, field groups, or rating criteria for every city.
For a small town, plan one Where to eat and drink page if separate restaurant, coffee-shop, and bar pages would be nearly empty. These are the two examples used below.
JReviews 6 Early Access. Enable Advanced Search Page and Listing List Pages in JReviews → Configuration → Early Access Settings before creating and checking these pages. Category and city filters use the Custom List settings without a PHP hook or SQL.
Search for listings in one city
Open Advanced Search, select the Hotels category and its listing type, choose Illinois and Chicago, and submit the search. Check a hotel that should appear and one in another city that should not. Copy the query string after ? from that working result.
An example is:
cat=23&query=all&usematch=1&jr_state=illinois&jr_city=chicago
Replace the category ID, field names, and stored option values with your own. A displayed label is not necessarily the stored value. Include the state when different places share a city name.
Save the city list as a page
Create a JReviews listing Custom List in the menu editor.
Paste the verified query string into Custom Parameters. Give it the title Hotels in Chicago, save it, and compare its results with the search from Search for listings in one city.
JReviews 5 and v6 Legacy
Use Custom Parameters for the city-and-category filters. Leave advanced query settings empty until you need a condition the ordinary filters cannot express.
If the list is empty or differs from the search, return to the working search and copy its stored values again. Do not add SQL or change field storage to repair a copied parameter.
If the page should list every matching business, keep pagination enabled. For a top-ten list, choose the sort order and use Page Total and Page Limit to limit the results.
JReviews 5. See the Custom Lists reference for the available page settings.
JReviews 6. See the Custom Lists reference for the available page settings.
Combine categories for a small town
Build the Where to eat and drink in Small Town result across food and drink categories. Check a restaurant, coffee shop, and bar that belong, plus a museum and a place in another town that do not.
Include selected categories
Use Custom Parameters to select the categories and city:
cat=24_25_26&query=all&jr_city=small-town
Here, 24, 25, and 26 represent the restaurant, coffee-shop, and bar categories. The earlier Hotels category uses example ID 23. All four IDs are illustrative. Use your own IDs and city value. Separate category IDs with underscores, as shown. Only those categories are included. Update the inclusion list when you add a category that belongs on this page.
Do not paste Listing.catid or cat_id into JSON Custom Query. That query format does not provide either category field.
Joomla, JReviews 5 and v6 Legacy: exclude categories instead
For this alternative, first create or retain a Leisure directory in JReviews and assign the restaurant, coffee-shop, bar, museum, cinema, and casino categories to it. Select the Leisure directory instead of a single category. In Custom Where, add the following condition to include the town and exclude unrelated categories:
Field.jr_city = '*small-town*' AND Listing.catid NOT IN (132,35,72)
Replace the excluded IDs with your museum, cinema, and casino categories. Replace small-town with the stored city option value. This exact equality example is for a single-select or radio field; legacy storage wraps that option value in asterisks. A multiple-option field needs a different comparison.
Keep the Leisure directory selected. Excluding a few categories from a site-wide query would still allow unrelated businesses. Choose either the inclusion example or this SQL exclusion rule. Test the result against the restaurant, coffee-shop, bar, museum, and other-town examples before linking the page.
Write the landing page and connect navigation
Write an introduction that helps visitors choose a business. For example, describe neighborhoods, transport options, or the criteria used to select the listings. Set the heading, document title, and meta description for that particular page.
Joomla. Edit the Custom List menu item. Set Page Title and Page Heading in Page Display, add the introduction in JReviews → Page Description, and set Meta Description in Metadata. For the Chicago hotel example, place the menu item beneath Chicago and use the alias hotels.
WordPress. Edit the page used for the Custom List. Set Page Title and Page Heading under Page & SEO Settings. Write the introduction in the page content area. JReviews also uses that content to generate the meta description.
After saving, check the visible introduction, page heading, document title, and meta description.
Link the city guide to its maintained lists. Add a clear route back to the city guide from hotel and restaurant pages. The Custom List's menu URL does not change each listing detail URL.
Keep the city guide available on individual listings
A visitor can arrive directly on a hotel from a search engine. Give that visitor links to the city guide and its other lists, plus content for that city. These links use the hotel's saved location, so they also work without a previous visit to the city list.
Create a listing field group named City navigation, or reuse Business location. Create a listing custom field labeled City guide, named jr_cityguide, with type Banner, and select that group in its Field Group setting. Associate the group with Hotel, Restaurant, and the other business listing types that use the city and state fields. Keep the Banner active and publicly readable, without dependencies. Leave its description empty, hide its label, and enable its display on the listing detail page. It is output-only, so submitters do not fill it in. Keep City and State publicly readable. Both are the single-selection Select fields created above.
Use the code for your selected setup below. Replace jr_city and jr_state if your field names differ. Replace chicago and illinois with their stored option values. Replace the example links with your site's published URLs.
Add the city navigation with Blade
Enable Listing Detail Page in Early Access. In the banner field's Advanced Settings → Blade template code, enter:
@if (in_array('chicago', (array) $listing->getFieldValue('jr_city', []), true)
&& in_array('illinois', (array) $listing->getFieldValue('jr_state', []), true))
<nav aria-label="City guide">
<a href="/">Home</a> >
<a href="/chicago">Chicago</a> >
<span aria-current="page">{{ $listing->title }}</span>
<ul>
<li><a href="/chicago/hotels">Hotels in Chicago</a></li>
<li><a href="/chicago/restaurants">Restaurants in Chicago</a></li>
</ul>
</nav>
<aside aria-label="Chicago travel information">
<p>Explore our Chicago guide for neighborhoods and transport information.</p>
<a href="/chicago/offers">View Chicago offers</a>
</aside>
@endif
The banner displays the city path, links to other Chicago lists, and Chicago-specific content on a Chicago listing. A listing in another city displays no banner. The listing title displays as text, so characters in the title cannot become HTML formatting.
Add the city navigation with PHP formatting
In the banner field's Advanced Settings → PHP output format, enter this code without an opening PHP tag:
$cities = (array) $CustomFields->fieldValue('jr_city', $entry);
$states = (array) $CustomFields->fieldValue('jr_state', $entry);
if (!in_array('chicago', $cities, true) || !in_array('illinois', $states, true)) {
return false;
}
$title = htmlspecialchars((string) ($entry['Listing']['title'] ?? ''), ENT_QUOTES, 'UTF-8');
return '<nav aria-label="City guide">'
. '<a href="/">Home</a> > <a href="/chicago">Chicago</a> > '
. '<span aria-current="page">'.$title.'</span>'
. '<ul><li><a href="/chicago/hotels">Hotels in Chicago</a></li>'
. '<li><a href="/chicago/restaurants">Restaurants in Chicago</a></li></ul>'
. '</nav><aside aria-label="Chicago travel information">'
. '<p>Explore our Chicago guide for neighborhoods and transport information.</p>'
. '<a href="/chicago/offers">View Chicago offers</a></aside>';
The banner displays the city path, links to other Chicago lists, and Chicago-specific content on a Chicago listing. A listing in another city displays no banner. The listing title displays as text, so characters in the title cannot become HTML formatting.
Keep your city guide links and any advertisement HTML in the banner's output. Use only trusted HTML that you control. To support another city, create another banner with its own location condition, links, and content. For a guide covering several neighboring cities, test membership against all the stored city values you want to include instead of testing only chicago.
The banner places the city links and content in the listing's field area. To keep existing CMS modules or widgets in the sidebar, use the steps in Keep city content in the CMS sidebar.
Keep the normal category link available for visitors who want businesses in other cities. The city links provide an additional route and do not change the listing's URL.
Keep city content in the CMS sidebar
Use your CMS sidebar for the city guide menu, advertising, galleries, or other modules and widgets. The rule below shows the selected content on the Chicago guide, its Custom Lists, and individual Chicago listings. It hides that content on other cities, ordinary category pages, and search pages. A visitor who opens a hotel directly gets the same Chicago sidebar.
Keep the city and state fields public. These examples read their saved single-select or radio values directly. Replace jr_city and jr_state if your field names differ. Replace *chicago* and *illinois* with your saved option values, including the asterisks. Do not use a translated label. The listing's saved values decide which sidebar appears. The menu or page used to reach the listing does not decide its city.
The rules control visibility only. Keep the CMS access settings on each module or widget and on the listing. Use the rule for public city content, not as an access restriction for private material.
Assign arbitrary Joomla modules by city
Use a custom site template or a child template that you maintain. In Joomla, a module chrome is the template file that wraps a module. This recipe adds one chrome named chicago.
- Note the article ID of your Chicago guide in Content → Articles. In this example it is
45. - Note the menu item IDs of Hotels in Chicago and Restaurants in Chicago. In this example they are
202and203. Each must be a JReviews Custom List. - Create
templates/YOUR_CUSTOM_TEMPLATE/html/layouts/chromes/chicago.phpwith the code below. Replace the IDs and saved location values near the top. Use the custom or child template's actual folder name. Do not put this file in a parent template that receives updates.
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
$app = Factory::getApplication();
$input = $app->getInput();
$allowed = $app->get('city_sidebar_chicago_allowed');
if ($allowed === null) {
$guideArticleIds = [45];
$listMenuIds = [202, 203];
$cities = ['*chicago*'];
$state = '*illinois*';
$allowed = false;
$option = $input->getCmd('option', '');
$view = $input->getCmd('view', '');
$route = trim($input->getString('url', ''), '/');
if ($option === 'com_content' && $view === 'article' && $route === ''
&& $input->getCmd('layout', '') !== 'edit' && $input->getCmd('task', '') === '') {
$articleId = (int) $input->getString('id');
if (in_array($articleId, $guideArticleIds, true)) {
$allowed = true;
} elseif ($articleId > 0) {
try {
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true)
->select($db->quoteName(['jr_city', 'jr_state']))
->from($db->quoteName('#__jreviews_content'))
->where($db->quoteName('contentid').' = '.$articleId);
$row = $db->setQuery($query)->loadObject();
$allowed = $row !== null
&& in_array((string) $row->jr_city, $cities, true)
&& (string) $row->jr_state === $state;
} catch (\Exception $exception) {
$allowed = false;
}
}
} elseif ($option === 'com_jreviews' && $view === 'category' && $route === '') {
$menu = $app->getMenu()->getActive();
$allowed = $menu !== null
&& in_array((int) $menu->id, $listMenuIds, true)
&& (int) $menu->getParams()->get('action') === 21;
}
$app->set('city_sidebar_chicago_allowed', $allowed);
}
$module = $displayData['module'];
if (!$allowed) {
$module->content = '';
return;
}
if ($module->content === null || $module->content === '') {
return;
}
?>
<aside class="city-guide-sidebar">
<?php if ($module->showtitle) : ?>
<h3><?php echo htmlspecialchars($module->title, ENT_QUOTES, 'UTF-8'); ?></h3>
<?php endif; ?>
<?php echo $module->content; ?>
</aside>
- Open the Chicago guide menu module. Select the sidebar position used by your template. Under Menu Assignment, select On all pages. Under Advanced → Module Style, select chicago from your custom template's group.
- Set Advanced → Caching to No caching for this module. This is required because a cache shared by menu ID can reuse a Chicago module on another city's listing.
- Repeat steps 4 and 5 for each Chicago advertisement, gallery, or other module. Keep the modules' own content and settings. Apply this chrome only to modules that belong to the Chicago sidebar.
- Publish the modules, retain their intended access levels, and clear the Joomla page and module caches. Clear any external page cache used by your site.
The guide article ID is an explicit Chicago page. Every other article uses its own saved city and state, even when it inherits a Chicago menu item. The menu IDs allow the two maintained Custom Lists. An ordinary category or search route does not become a Chicago page because it inherits one of those menu IDs.
Use a sidebar position that renders modules through Joomla's normal module chrome. A template helper that requests raw module content bypasses Module Style. For that case, place the modules in a normal template position or adjust your own child-template sidebar to use Joomla's normal module renderer. Do not edit Joomla or JReviews files. The template can reserve an empty sidebar column even when its modules produce no output. Adjust that layout in your custom template if the column must collapse.
Assign arbitrary WordPress widgets by city
Use a widget area in your theme, such as the right sidebar under Appearance → Widgets. Add your Chicago navigation, advertisement, gallery, or other widgets to that area. A block placed in a widget area is supported too. A block placed directly in a Site Editor template is not a sidebar widget.
First, identify the exact saved widget IDs. Titles such as "Chicago guide" are not widget IDs.
- Create
wp-content/mu-plugins/sidebar-widget-ids.phpwith the inventory code below. Createmu-pluginsif it does not exist. WordPress loads PHP files placed directly in this folder without an activation step. - While signed in as an administrator who can edit theme options, open Tools → Sidebar widget IDs.
- Match the sidebar name and numbered position with Appearance → Widgets. Copy the IDs of your Chicago widgets, such as
nav_menu-3andblock-7. A top-level Group block is one widget. Its inner blocks use the Group's widget ID. - Delete
sidebar-widget-ids.phpafter you record the IDs. The inventory only reads the saved widget arrangement.
<?php
/**
* Plugin Name: Sidebar widget IDs
*/
defined('ABSPATH') || exit;
add_action('admin_menu', static function (): void {
add_management_page('Sidebar widget IDs', 'Sidebar widget IDs', 'edit_theme_options', 'sidebar-widget-ids', static function (): void {
if (!current_user_can('edit_theme_options')) {
return;
}
global $wp_registered_sidebars, $wp_registered_widgets;
echo '<div class="wrap"><h1>Sidebar widget IDs</h1><table class="widefat"><thead><tr>';
echo '<th>Sidebar</th><th>Position</th><th>Widget ID</th><th>Widget type</th></tr></thead><tbody>';
foreach ((array) get_option('sidebars_widgets', []) as $sidebar => $ids) {
if (!is_array($ids) || !isset($wp_registered_sidebars[$sidebar])) {
continue;
}
foreach (array_values($ids) as $position => $id) {
echo '<tr><td>'.esc_html($wp_registered_sidebars[$sidebar]['name']).'</td>';
echo '<td>'.esc_html((string) ($position + 1)).'</td>';
echo '<td><code>'.esc_html($id).'</code></td>';
echo '<td>'.esc_html($wp_registered_widgets[$id]['name'] ?? 'Unavailable widget').'</td></tr>';
}
}
echo '</tbody></table></div>';
});
});
Create wp-content/mu-plugins/city-guide-sidebar.php with the following code. Replace $widgetIds with the IDs you recorded. Replace $pageIds with the WordPress page IDs of the Chicago guide, Hotels in Chicago, and Restaurants in Chicago. You can read a page's ID from post=123 in its editing URL. Replace the saved location values too.
<?php
/**
* Plugin Name: City guide sidebar
*/
defined('ABSPATH') || exit;
add_action('wp', static function (): void {
if (is_admin()) {
return;
}
$widgetIds = ['nav_menu-3', 'block-7'];
$pageIds = [101, 102, 103];
$cities = ['*chicago*'];
$state = '*illinois*';
$allowed = false;
if (!is_404() && !is_search() && !is_category() && !is_tax()) {
if (is_singular('post')) {
$post = get_queried_object();
if ($post instanceof WP_Post && $post->post_status === 'publish' && !post_password_required($post)) {
global $wpdb;
$row = $wpdb->get_row($wpdb->prepare(
"SELECT jr_city, jr_state FROM {$wpdb->prefix}jreviews_content WHERE contentid = %d",
get_queried_object_id()
));
$allowed = $row !== null
&& in_array((string) $row->jr_city, $cities, true)
&& (string) $row->jr_state === $state;
}
} elseif (is_page($pageIds) && (string) get_query_var('url') === '' && (string) get_query_var('plugin') === '') {
$allowed = true;
}
}
if (!$allowed) {
add_filter('sidebars_widgets', static function (array $sidebars) use ($widgetIds): array {
foreach ($sidebars as $sidebar => $ids) {
if (is_array($ids)) {
$sidebars[$sidebar] = array_values(array_diff($ids, $widgetIds));
}
}
return $sidebars;
});
}
});
WordPress now removes those widget IDs from sidebar output on other pages. Other widgets keep their normal placement. The rule does not save a new widget arrangement, so your widgets remain available in the editor.
If you delete and recreate a widget, record its new ID and update $widgetIds. If another widget-visibility plugin also controls these widgets, its restrictions still apply. Disable any cache that stores a whole sidebar across different page URLs. Clear your page, sidebar, and CDN caches after installing this rule or changing a listing's saved location.
To cover several neighboring cities, add each saved city option to $cities, for example ['*mendoza*', '*las-heras*', '*godoy-cruz*']. Set the state's saved value too. Keep every city in that array in the same state. Add the guide and Custom List IDs for that area. For a separate city sidebar, keep its configuration separate.
Create a separate Joomla chrome with its own values and filename. In each copy, replace both occurrences of city_sidebar_chicago_allowed with the same unique name for that sidebar. For example, use a name containing the new city's name. This keeps one city's visibility result from being reused for another city's modules.
Create a separate WordPress file with its own saved values, page IDs, and widget IDs.
Check the sidebar as a logged-out visitor. Open the Chicago guide, both Custom Lists, and a Chicago listing directly. Open a different city's listing directly, and open it through a Chicago menu context if your routing permits that. Chicago modules or widgets must remain absent. Also check an ordinary category, a search page, and a listing without a saved city. Change one test listing's city, clear the page caches, and confirm that its sidebar changes. No previous visit, referrer, session value, or first search result is needed.
Test the city pages and navigation
As a logged-out visitor, open the city guide, follow Hotels, open a hotel, and navigate back to the city guide. Test the combined small-town list, a later results page, and the page's introduction and metadata.
Open a Chicago hotel directly in a new browser tab, follow its city guide and restaurant links, and check its Chicago content. Open a hotel in another city and confirm that the Chicago banner is absent. Check that no empty banner remains. Check the sidebar cases in Keep city content in the CMS sidebar too. Use the crawl, indexing, and canonical guide before deciding which landing and filter URLs search engines should index.
Learn more
- Custom Lists (v5)
- Custom Lists (v6)
- Early Access (v6)
- Json Query Builder (v6)