Let's adjust the code to display the filters normally without collapsing them, and fix the "Show More" button functionality. We'll ensure the initial set of brands displayed is limited, with the option to display more when the button is clicked.
Here's the complete code for your WordPress custom HTML block:
<!-- Brand Finder Tool Start -->
<style>
.brand-finder {
font-family: Arial, sans-serif;
max-width: 700px;
margin: 10px auto;
padding: 15px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.brand-finder h2 {
text-align: center;
font-size: 20px;
margin-bottom: 8px;
}
.brand-finder p {
text-align: center;
font-size: 14px;
margin-bottom: 15px;
}
.filters {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 20px;
}
.filter {
flex: 1 1 150px;
display: flex;
flex-direction: column;
}
.filter label {
font-weight: bold;
margin-bottom: 5px;
font-size: 12px;
}
.filter select {
padding: 6px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 12px;
}
#brandList {
list-style-type: none;
padding: 0;
margin: 0;
}
#brandList li {
background-color: #f9f9f9;
margin-bottom: 8px;
padding: 10px;
border-radius: 6px;
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
transition: background-color 0.3s;
}
#brandList li:hover {
background-color: #f1f1f1;
}
.show-more-button {
text-align: center;
margin: 20px 0;
}
.show-more-button button {
font-size: 14px;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
background-color: #f0f0f0;
cursor: pointer;
}
@media (max-width: 600px) {
.filters {
flex-direction: column;
}
.filter {
width: 100%;
}
}
</style>
<div class="brand-finder">
<h2>Affordable Brand Finder Tool</h2>
<p>Discover affordable Canadian clothing brands that match your preferences. Use the filters below to find your perfect fit!</p>
<div class="filters" id="filters">
<div class="filter">
<label for="priceRange">Price Range:</label>
<select id="priceRange">
<option value="all">All</option>
<option value="budget">Budget</option>
<option value="midRange">Mid-Range</option>
<option value="premium">Premium</option>
</select>
</div>
<div class="filter">
<label for="style">Style:</label>
<select id="style">
<option value="all">All</option>
<option value="casual">Casual</option>
<option value="formal">Formal</option>
<option value="athletic">Athletic</option>
<option value="plusSize">Plus-Size</option>
<option value="vintage">Vintage</option>
<option value="loungewear">Loungewear</option>
</select>
</div>
<div class="filter">
<label for="sustainability">Sustainability:</label>
<select id="sustainability">
<option value="all">All</option>
<option value="eco-friendly">Eco-Friendly</option>
<option value="standard">Standard</option>
</select>
</div>
</div>
<ul id="brandList"></ul>
<div class="show-more-button" style="display: none;">
<button onclick="showMore()">Show More</button>
</div>
</div>
<script>
(function(){
const brands = [
{ name: "Ardene", priceRange: "budget", style: "casual", sustainability: "standard" },
{ name: "Joe Fresh", priceRange: "budget", style: "casual", sustainability: "standard" },
{ name: "Old Navy", priceRange: "budget", style: "casual", sustainability: "standard" },
{ name: "Simons' OFF!", priceRange: "midRange", style: "formal", sustainability: "standard" },
{ name: "Forever 21", priceRange: "budget", style: "casual", sustainability: "eco-friendly" },
{ name: "Reitmans", priceRange: "midRange", style: "plusSize", sustainability: "standard" },
{ name: "Penningtons", priceRange: "budget", style: "plusSize", sustainability: "standard" },
{ name: "Addition Elle", priceRange: "budget", style: "plusSize", sustainability: "standard" },
{ name: "Dynamite", priceRange: "budget", style: "casual", sustainability: "standard" },
{ name: "H&M", priceRange: "budget", style: "casual", sustainability: "eco-friendly" },
{ name: "Lululemon", priceRange: "premium", style: "athletic", sustainability: "eco-friendly" },
{ name: "Poshmark", priceRange: "budget", style: "vintage", sustainability: "eco-friendly" },
{ name: "Tentree", priceRange: "midRange", style: "casual", sustainability: "eco-friendly" },
{ name: "Frank and Oak", priceRange: "midRange", style: "formal", sustainability: "eco-friendly" },
{ name: "Knix", priceRange: "midRange", style: "loungewear", sustainability: "eco-friendly" },
{ name: "Fresh Fashion Library", priceRange: "budget", style: "casual", sustainability: "eco-friendly" },
{ name: "The FitzRoy", priceRange: "premium", style: "formal", sustainability: "eco-friendly" },
];
let limit = 5;
function filterBrands() {
const priceRange = document.getElementById("priceRange").value;
const style = document.getElementById("style").value;
const sustainability = document.getElementById("sustainability").value;
const filteredBrands = brands.filter(brand =>
(priceRange === "all" || brand.priceRange === priceRange) &&
(style === "all" || brand.style === style) &&
(sustainability === "all" || brand.sustainability === sustainability)
);
displayBrands(filteredBrands.slice(0, limit));
// Show or hide "Show More" button based on remaining brands
const showMoreButton = document.querySelector(".show-more-button");
if (filteredBrands.length > limit) {
showMoreButton.style.display = 'block';
} else {
showMoreButton.style.display = 'none';
}
}
function displayBrands(brandsToDisplay) {
const brandList = document.getElementById("brandList");
brandList.innerHTML = "";
if (brandsToDisplay.length === 0) {
const li = document.createElement("li");
li.textContent = "No brands match your criteria.";
brandList.appendChild(li);
return;
}
brandsToDisplay.forEach(brand => {
const li = document.createElement("li");
li.innerHTML = `<strong>${brand.name}</strong><br>
Price Range: ${capitalize(brand.priceRange)}<br>
Style: ${formatStyle(brand.style)}<br>
Sustainability: ${formatSustainability(brand.sustainability)}`;
brandList.appendChild(li);
});
}
function showMore() {
limit += 5;
filterBrands();
}
function capitalize(word) {
if (!word) return "";
const formatted = word.replace(/([A-Z])/g, ' $1');
return formatted.charAt(0).toUpperCase() + formatted.slice(1);
}
function formatStyle(style) {
switch(style) {
case "plusSize":
return "Plus-Size";
case "loungewear":
return "Loungewear";
case "vintage":
return "Vintage";
default:
return capitalize(style);
}
}
function formatSustainability(sustainability) {
return sustainability === "eco-friendly" ? "Eco-Friendly" : "Standard";
}
document.addEventListener("DOMContentLoaded", function(){
document.getElementById("priceRange").addEventListener("change", filterBrands);
document.getElementById("style").addEventListener("change", filterBrands);
document.getElementById("sustainability").addEventListener("change", filterBrands);
filterBrands();
});
})();
</script>
<!-- Brand Finder Tool End -->
Updates Made
-
Filters are Always Visible: The filters are displayed normally without the need for toggling.
-
"Show More" Functionality: The "Show More" button functionality is now correctly checking if there are more brands to display and increments the number of brands shown by 5 each time it is pressed.
-
Responsive Design: The filters remain horizontally flexible and stack when the screen size is small.
This configuration will keep the tool compact while allowing users to see more brands by clicking "Show More". Adjust any of the parameters, especially the limit, to fit your specific needs.