Reputation: 19
I have a WordPress ecommerce site that uses the Shoptimizer theme. I wrote a custom sidebar menu in HTML and CSS which I thought we would use on the website, however I've now decided a sidebar menu isn't the way to go.
The whole sidebar menu expands / collapses from a single button, so I would like that button / the complete menu to be integrated into the main navigation menu on the site. However i'm really struggling to understand how to add custom HTML into the navigation menu. I've seen several posts mention the walker class, be these posts don't seem to be using that to add their html?
Can anyone tell me how I could add my custom HTM into the navigation menu? my custom HTML, JS & CSS is below:
function toggleCategories() {
const categories = document.getElementById('main-categories');
categories.style.display = categories.style.display === 'none' ? 'block' : 'none';
}
function toggleSubcategories(id) {
// Find all main categories
const allCategories = document.querySelectorAll(".category");
allCategories.forEach((category) => {
const subcategory = category.nextElementSibling; // Assuming subcategories immediately follow their parent categories
if (subcategory && subcategory.id !== id) {
// Collapse other categories
subcategory.style.display = "none";
// Collapse all nested subcategories
const nestedSubcategories = subcategory.querySelectorAll(".subcategory");
nestedSubcategories.forEach((nested) => {
nested.style.display = "none";
});
}
});
// Toggle the clicked category
const clickedSubcategory = document.getElementById(id);
if (clickedSubcategory.style.display === "none" || clickedSubcategory.style.display === "") {
clickedSubcategory.style.display = "block";
// Expand all nested subcategories
const nestedSubcategories = clickedSubcategory.querySelectorAll(".subcategory");
nestedSubcategories.forEach((nested) => {
nested.style.display = "block";
});
} else {
clickedSubcategory.style.display = "none";
// Collapse all nested subcategories
const nestedSubcategories = clickedSubcategory.querySelectorAll(".subcategory");
nestedSubcategories.forEach((nested) => {
nested.style.display = "none";
});
}
}
body {
font-family: Arial, sans-serif;
}
.sidebar {
width: 300px;
background-color: #f8f9fa;
padding: 10px;
border: 1px solid #ddd;
}
.sidebar-title {
font-weight: bold;
font-size: 2em;
text-align: center;
}
.category {
cursor: pointer;
margin: 5px 0;
padding: 8px;
background-color: #e9ecef;
border-radius: 5px;
transition: background-color 0.3s;
}
.category:hover {
background-color: #d6d8db;
}
.subcategory {
margin-left: 10px;
display: none;
padding: 5px 0;
}
.subcategory a {
text-decoration: none;
color: #007bff;
}
.subcategory a:hover {
text-decoration: underline;
}
.link-hover {
position: relative;
line-height: 1.75;
width: auto;
}
.link-hover .image-hover {
display: none;
position: absolute;
left: 15em;
top: 0;
/* Adjust as needed */
z-index: 9999;
/* Ensure it appears above other elements */
border: 1px solid #ddd;
/* Optional: Add border to distinguish it */
background-color: white;
/* Optional: Set background to prevent overlap issues */
padding: 5px;
/* Optional: Add padding for a neat appearance */
aspect-ratio: 1 / 1;
/* Maintain 1:1 aspect ratio */
width: 300px;
height: auto;
/* Allow height to adjust naturally */
object-fit: contain;
overflow: hidden;
box-sizing: border-box;
text-align: center;
/* Centering */
line-height: 150px;
/* Matches height for vertical centering */
min-width: 300px;
/* Prevent shrinking */
min-height: 300px;
}
.link-hover:hover .image-hover {
position: absolute;
left: 15em;
display: block;
}
<div class="sidebar">
<button class="sidebar-title" onclick="toggleCategories()">All Startrite Spares</button>
<div id="main-categories" style="display: none;">
<div class="category" onclick="toggleSubcategories('horizontal-spares')">Horizontal Bandsaw Spares</div>
<div id="horizontal-spares" class="subcategory">
<div class="category" onclick="toggleSubcategories('h-series')">H Series</div>
<div id="h-series" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/h175/">Startrite H175
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/H175-GRAPHIC-2.webp" class="image-hover" alt="Startrite H175 Diagram horiztonal bandsaw diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/h200/">Startrite H200
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/H200-GRAPHIC-2.webp" class="image-hover" alt="Startrite H200 Diagram horiztonal bandsaw diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/h225/">Startrite H225
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/01/H225-GRAPHIC.webp" class="image-hover" alt="Startrite H225 Diagram horiztonal bandsaw diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/h250-h330/">Startrite H250 & H330
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/01/H250-330-GRAPHIC.webp" class="image-hover" alt="Startrite H250 & H330 horiztonal bandsaw diagram">
</a>
<br>
</div>
<div class="category" onclick="toggleSubcategories('hb')">HB Series</div>
<div id="hb" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/hb-series/">All HB (Startrite HB225-HB330)
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/HB225-250-280-330-GRAPHIC-2.webp" class="image-hover" alt="Startrite HB Diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/hb-series/">H280MV & H280M4
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/HB225-250-280-330-GRAPHIC-2.webp" class="image-hover" alt="Startrite H4 & HV Diagram">
</a>
<br>
</div>
<div class="category" onclick="toggleSubcategories('meba-metora')">MEBA & METORA</div>
<div id="meba-metora" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/meba/">MEBA SM250 & SM320
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/05/MEBA-SM250-320-GRAPHIC.webp" class="image-hover" alt="Startrite MEBA SM250 & SM320 Bandsaws Diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/horizontal-spares/metora/">METORA
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/08/METORA-UMB-220-GRAPHIC.jpg" class="image-hover" alt="Startrite METORA Horizontal Bandsaw Diagram">
</a>
</div>
</div>
<div class="category" onclick="toggleSubcategories('vertical-spares')">Vertical Bandsaw Spares</div>
<div id="vertical-spares" class="subcategory">
<div class="category" onclick="toggleSubcategories('small-verticals')">Woodworking Verticals</div>
<div id="small-verticals" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/301/">301, 301S & 301E
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/301-301S-GRAPHIC-resized-2.webp" class="image-hover" alt="Startrite 301 or 301S vertical bandsaw Diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/351-352/">351 & 352
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/352-352S-GRAPHIC-2.webp" class="image-hover" alt="Startrite 351 & 352 vertical bandsaw drawing">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/351s-352s/">351S & 352S
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/352S-photo.webp" class="image-hover" alt="Diagram of a Startrite 351S & 352S vertical bandsaws">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/12s-bandit/">BANDIT & 12-S
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/12S1-12S5-12S10-BANDIT-GRAPHIC-2.webp" class="image-hover" alt="Diagram of a Startrite bandit bandsaw, also know as the 12-S">
</a>
<br>
</div>
<div class="category" onclick="toggleSubcategories('medium-verticals')">Medium Verticals</div>
<div id="medium-verticals" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/small-verticals/">V, T, R & S Series Bandsaws (Most Popular)
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/SMALL-VERTICALS-GRAPHIC-2.webp" class="image-hover" alt="Diagram of the Startrite V, T, R or S series bandsaw, the flag ship vertical bandsaw range by Startrite">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/502/">502 with Footbrake
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/502-VB-GRAPHIC-2.webp" class="image-hover" alt="Diagram of the Startrite 502 series bandsaw">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/502s/">502S
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/502S.webp" class="image-hover" alt="Startrite 502S vertical bandsaw diagram">
</a>
<br>
</div>
<div class="category" onclick="toggleSubcategories('industrial-verticals')">Industrial Verticals</div>
<div id="industrial-verticals" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/216-316/">216 & 316
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/216-316-GRAPHIC-2.webp" class="image-hover" alt="Diagram of the Startrite 316 industrial bandsaw, the flag ship vertical bandsaw range by Startrite">
<br>
</a>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/v500/">V500
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/V500-GRAPHIC-2.webp" class="image-hover" alt="Diagram of the Startrite V500 industrial bandsaw">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/vertical-spares/v900/">V900
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/V900-GRAPHIC-2.webp" class="image-hover" alt="diagram of the Startrite V900 industrial bandsaw">
</a>
<br>
</div>
</div>
<div class="category" onclick="toggleSubcategories('table-saw-spares')">Table Saw Spares</div>
<div id="table-saw-spares" class="subcategory">
<div class="category" onclick="toggleSubcategories('tilt-arbor')">Tilt Arbor</div>
<div id="tilt-arbour" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/circular-spares/ta145-ta165/">TA145 & TA165
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/TA-145-GRAPHIC.webp" class="image-hover" alt="Diagram of the Startrite TA145 & Ta165 Table Saws">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/circular-spares/ta175-ta275/">TA175 & TA275
<img src="https://startrite-spares.co.uk/wp-content/uploads/2023/12/Startrite-TA-Table-Saws.webp" class="image-hover" alt="TA175 & TA275 Drawing. This is the most popular saw in the Startrite Table saw range">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/circular-spares/ta255/">TA255
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/TA-255-GRAPHIC.webp" class="image-hover" alt="Diagram of a Startrite TA255 Table Saw">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/circular-spares/ta300/">TA300
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/05/TA-300-GRAPHIC.webp" class="image-hover" alt="Diagram of a Startrite TA300 Table Saw">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/circular-spares/ta-1250/">TA1250
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/05/TA-1250-GRAPHIC.webp" class="image-hover" alt="Diagram of a Startrite TA1250 Table Saw">
</a>
<br>
</div>
</div>
<div class="category" onclick="toggleSubcategories('cutoff-saw-spares')">Metal Cut Off Saws</div>
<div id="cutoff-saw-spares" class="subcategory">
<div class="category" onclick="toggleSubcategories('cutoff-saws')">Cut Off Saws</div>
<div id="cutoff-saws" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/cutoff-spares/cf250-cf275-cf315/">CF250, CF275 & CF315
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/CF215-275-GRAPHIC-2.webp" class="image-hover" alt="Startrite CF250, CF275 & CF315 Cut-off saw Diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/cutoff-spares/cf350/">CF350
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/CF315-350M-GRAPHIC-2.webp" class="image-hover" alt="Startrite CF350 Cut-off saw Diagram">
</a>
<br>
</div>
</div>
<div class="category" onclick="toggleSubcategories('saw-blades')">Saw Blades</div>
<div id="saw-blades" class="subcategory">
<div class="category" onclick="toggleSubcategories('bandsaw-blades')">All Blades</div>
<div id="bandsaw-blades" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/blades/horizontal-bandsaw-blades/">Horizontal Bandsaw Blades
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/05/Metal-Cutting-Bandsaw-Blades.webp" class="image-hover" alt="diagram of a horizontal bandsaw">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/blades/vertical-bandsaw-blades-wood/">Vertical Bandsaw Blades - WOOD CUTTING
<img src="https://startrite-spares.co.uk/wp-content/uploads/2023/12/Wood-Cutting-Bandsaw-Blades.webp" class="image-hover" alt="Wood cutting bandsaw blade, on a Startrite bandsaw">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/blades/vertical-bandsaw-blades-metal/">Vertical Bandsaw Blades - METAL CUTTING
<img src="https://startrite-spares.co.uk/wp-content/uploads/2023/12/Wood-Cutting-Bandsaw-Blades.webp" class="image-hover" alt="Metal cutting bandsaw blade, on a Startrite bandsaw">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/blades/circular-saw-blades/">Table Saw Blades
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/CF315-350M-GRAPHIC-2.webp" class="image-hover" alt="diagram of a table saw blade">
</a>
<br>
</div>
</div>
<div class="category" onclick="toggleSubcategories('pillar-drills')">Pillar Drill Spares</div>
<div id="pillar-drills" class="subcategory">
<div class="category" onclick="toggleSubcategories('mercury-spares')">Startrite Mercury Drills</div>
<div id="mercury-spares" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/drills-extractors/pillar-drill-spares/mercury-5/">Mercury - 5 Speed
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/MERCURY-DRILL-5-SPEED-GRAPHIC-2.webp" class="image-hover" alt="Diagram of a 5 speed Startrite Mercury Drill">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/drills-extractors/pillar-drill-spares/mercury-10/">Mercury - 10 Speed
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/MERCURY-DRILL-10-SPEED-GRAPHIC-2.webp" class="image-hover" alt="Startrite Mercury 10 Speed diagram">
</a>
<br>
</div>
</div>
<div class="category" onclick="toggleSubcategories('dust-extractors')">Dust Extractor Spares</div>
<div id="dust-extractors" class="subcategory">
<div class="category" onclick="toggleSubcategories('cyclair-mde')">Startrite Extractors</div>
<div id="cyclair-mde" class="subcategory">
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/drills-extractors/extractor-spares/cyclair/">Cyclair 55 & 75
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/CYCLAIR-55-75-GRAPHIC-2.webp" class="image-hover" alt="Cyclair 55 & Cyclair 75 Dust Extractor diagram">
</a>
<br>
<a class="link-hover" href="https://startrite-spares.co.uk/startrite/drills-extractors/extractor-spares/mde/">MDE2 & MDE3
<img src="https://startrite-spares.co.uk/wp-content/uploads/2024/03/MDE-23-GRAPHIC-2.webp" class="image-hover" alt="drawing of a Startrite MDE2 dust extractor">
</a>
<br>
</div>
</div>
</div>
Upvotes: -1
Views: 97
Reputation: 9
For websites using a CMS like WordPress:
Upvotes: 0