Магазин

.categories-block {
max-width: 1200px;
margin: 0 auto;
padding: 40px 20px;
font-family: -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, sans-serif;
}

.categories-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 24px;
}

.category-loader {
grid-column: 1 / -1;
text-align: center;
padding: 40px;
color: #999;
font-size: 16px;
}

.category-card {
background: #ffffff;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
transition: all 0.3s ease;
opacity: 0;
transform: translateY(20px);
}

.category-card.loaded {
opacity: 1;
transform: translateY(0);
}

.category-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.category-link {
display: flex;
flex-direction: column;
text-decoration: none;
color: inherit;
height: 100%;
}

.category-image {
width: 100%;
height: 200px;
overflow: hidden;
background: #f5f5f5;
position: relative;
}

.category-image img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}

.category-card:hover .category-image img {
transform: scale(1.05);
}

.category-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
font-size: 48px;
font-weight: 700;
}

.category-content {
padding: 20px;
flex: 1;
display: flex;
flex-direction: column;
}

.category-title {
font-size: 20px;
font-weight: 600;
color: #1a1a1a;
margin: 0 0 8px 0;
}

.category-description {
font-size: 14px;
color: #666;
line-height: 1.5;
margin: 0 0 16px 0;
flex: 1;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}

.category-meta {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: auto;
}

.category-count {
font-size: 13px;
color: #999;
}

.category-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 8px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}

.category-btn:hover {
transform: scale(1.05);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Мобильная версия */
@media (max-width: 768px) {
.categories-grid {
grid-template-columns: 1fr;
gap: 16px;
}

.category-card {
border-radius: 12px;
}

.category-link {
flex-direction: row;
align-items: center;
}

.category-image {
width: 120px;
height: 120px;
flex-shrink: 0;
}

.category-placeholder {
font-size: 32px;
}

.category-content {
padding: 16px;
flex: 1;
}

.category-title {
font-size: 16px;
margin-bottom: 4px;
}

.category-description {
font-size: 13px;
margin-bottom: 12px;
}

.category-meta {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}

.category-btn {
width: 100%;
padding: 8px 16px;
font-size: 13px;
}
}

@media (max-width: 480px) {
.categories-block {
padding: 20px 12px;
}

.category-image {
width: 100px;
height: 100px;
}

.category-title {
font-size: 15px;
}
}

document.addEventListener(‘DOMContentLoaded’, function() {
const grid = document.getElementById(‘categoriesGrid’);
if (!grid) return;

// Получаем категории через WP REST API
fetch(‘/wp-json/wp/v2/product_cat?per_page=6&_fields=id,name,description,count,link,meta’)
.then(response => response.json())
.then(categories => {
grid.innerHTML = »;

if (!categories || categories.length === 0) {
grid.innerHTML = ‘

Категории не найдены

‘;
return;
}

// Получаем изображения для категорий
const imagePromises = categories.map(cat => {
return fetch(`/wp-json/wp/v2/media?meta_key=_thumbnail_id&meta_value=${cat.id}`)
.then(r => r.json())
.then(media => {
if (media && media.length > 0 && media[0].source_url) {
return { id: cat.id, image: media[0].source_url };
}
return { id: cat.id, image: null };
})
.catch(() => ({ id: cat.id, image: null }));
});

Promise.all(imagePromises).then(images => {
const imageMap = {};
images.forEach(img => { imageMap[img.id] = img.image; });

categories.forEach((cat, index) => {
const image = imageMap[cat.id];
const description = cat.description ? cat.description.replace(/]*>/g, ») : »;
const shortDesc = description.length > 80 ? description.substring(0, 80) + ‘…’ : description;
const firstLetter = cat.name.charAt(0).toUpperCase();

const card = document.createElement(‘div’);
card.className = ‘category-card’;
card.innerHTML = `

${image
? `${cat.name}`
: `

${firstLetter}

`
}

${cat.name}

${shortDesc ? `

${shortDesc}

` : »}

${cat.count} товаров


`;

grid.appendChild(card);

// Анимация появления с задержкой
setTimeout(() => {
card.classList.add(‘loaded’);
}, index * 100);
});
});
})
.catch(error => {
console.error(‘Ошибка загрузки категорий:’, error);
grid.innerHTML = ‘

Не удалось загрузить категории

‘;
});
});

Загрузка категорий…

6개 결과 모두 표시