Create an account to edit articles | See Formatting Syntax for Wiki syntax | We look forward to your contribution!
You are here: The ProductCart Encyclopedia » How To's » Displaying different content depending on which category is shown
Displaying different content depending on which category is shown
Overview
What if you wanted to change elements of your store design (e.g. navigation, graphics, etc.) depending on which category the customer is viewing? You can do so by using conditional statements based on the category ID. You can find out the ID of a category in many ways. For example, when editing the category in the Control Panel, look at the number that follows ?idcategory= in the browser address field.
In the storefront, the category ID is loaded onto the page (viewcategories.asp) before header.asp and footer.asp are invoked. Therefore, you can place conditional statements in those files with the assumption that the category ID is known.
Example: one category
Here is a simple example. Let's assume you want to show something different when a certain category is shown. If it's just one category that you need to work with, you can use a simple “IF” statement. For instance, let's assume the category number is 100. The ASP code would be:
<% if pIdCategory=100 then %> Show special content to be displayed when category 100 is shown <% else %> Show something else <% end if %>
Example: multiple categories
If you want to show different content depending on the category shown, and you are dealing with a number of different categories, the you will want to use a “SELECT CASE” statement. The ASP code in that case would be:
<%
Select Case pIdCategory
Case 100
response.write("Show this message when category 100 is loaded.")
Case 101
response.write("Show this message when category 101 is loaded")
Case 102
%>
<strong>Use this HTML code when category 102 is loaded</strong>.
<%
Case else
document.write("Show this message when other categories are loaded.")
End Select
%>
Other notes
- This article can certainly be expanded with additional, more complex examples.
Trace: » Adding a product to the cart from anywhere » Manage Help Desk » Welcome to ProductCart » Default Preferences » How ProductCart is licensed » How Custom Search Fields are Stored in the ProductCart Database » Activating your store: ProductCart Setup Wizard » Importing Product Categories » Activating the ProductCart eBay Add-on » Displaying different content depending on which category is shown