Задать вопрос
@bett22

Как сделать фильтрацию в каталоге товаров?

Решил научится натягивать простой сайт на wordpress. Проблема возникла с фильтрацией на странице http://geniuscontraction/%d0%bc%d0%be%d1%81%d0%ba%... . Что не так? Почему не фильтрует?

<div class="page__catalog catalog">
				<div class="catalog__container">
					<h1><?php the_title(); ?></h1>
					<div class="catalog__content">
					<nav class="catalog__navigation navigation-catalog scroll">
						<div class="navigation-catalog__titles">
							<div class="navigation-catalog__title">
								<div data-filter="all" class="navigation-catalog__item _active">
									<div class="navigation-catalog__image">
										<picture><source srcset="img/products/product-1.webp" type="image/webp"><img src="img/products/product-1.png" alt=""></picture>
									</div>
									<p>Все</p>
								</div>
							</div>
							<div class="navigation-catalog__title">
								<div data-filter="<?php echo get_category( 13, ARRAY_A)['slug']?>" class="navigation-catalog__item">
									<div class="navigation-catalog__image">
										<picture><source srcset="img/products/product-1.webp" type="image/webp"><img src="img/products/product-1.png" alt=""></picture>
									</div>
									<p><?php echo get_category( 13, ARRAY_A)['name']?></p>
								</div>
							</div>
							<div class="navigation-catalog__title">
								<div data-filter="<?php echo get_category( 14, ARRAY_A)['slug']?>" class="navigation-catalog__item">
									<div class="navigation-catalog__image">
										<picture><source srcset="img/products/product-2.webp" type="image/webp"><img src="img/products/product-2.png" alt=""></picture>
									</div>
									<p><?php echo get_category( 14, ARRAY_A)['name']?></p>
								</div>
							</div>
							<div class="navigation-catalog__title">
								<div data-filter="<?php echo get_category( 15, ARRAY_A)['slug']?>" class="navigation-catalog__item">
									<div class="navigation-catalog__image">
										<picture><source srcset="img/products/product-3.webp" type="image/webp"><img src="img/products/product-3.png" alt=""></picture>
									</div>
									<p><?php echo get_category( 15, ARRAY_A)['name']?></p>
								</div>
							</div>
							<div class="navigation-catalog__title">
								<div data-filter="<?php echo get_category( 16, ARRAY_A)['slug']?>" class="navigation-catalog__item">
									<div class="navigation-catalog__image">
										<picture><source srcset="img/products/product-4.webp" type="image/webp"><img src="img/products/product-4.png" alt=""></picture>
									</div>
									<p><?php echo get_category( 16, ARRAY_A)['name']?></p>
								</div>
							</div>
							<div class="navigation-catalog__title">
								<div data-filter="<?php echo get_category( 17, ARRAY_A)['slug']?>" class="navigation-catalog__item">
									<div class="navigation-catalog__image">
										<picture><source srcset="img/products/product-5.webp" type="image/webp"><img src="img/products/product-5.png" alt=""></picture>
									</div>
									<p><?php echo get_category( 17, ARRAY_A)['name']?></p>
								</div>
							</div>
						</div>
					</nav>
					<div class="catalog__body">

						<?php

						global $post;

						if(have_posts()){
							while(have_posts()){
							the_post();
							$all_category = get_the_category();
							$res_name = '';
							foreach($all_category as $category){
								if($category -> term_id == 13 || $category -> term_id == 14 || $category -> term_id == 15 || $category -> term_id == 16 || $category -> term_id == 17){
									$res_name = $category -> slug;
								}
							}
							?>

							<?php

							}
							
						}

						$myposts = get_posts([ 
							'numberposts' => -1,
							'category'    => 12,
						]);

						if( $myposts ){
							foreach( $myposts as $post ){
								setup_postdata( $post );
								?>

								<div class="catalog__column <?php $res_name?>">
									<div class="catalog__item">
										<div class="catalog__image">
											<div class="catalog__favorites">
												<div class="catalog__favorites-icon _icon-favorites-2"></div>
												<div class="catalog__favorites-icon-bg _icon-favorites"></div>
												<div class="catalog__like">2549</div>
											</div>
											<?php the_post_thumbnail(); ?>
										</div>
										<a href="<?php echo get_permalink(); ?>" class="catalog__items">
											<h3><?php the_title(); ?></h3>
										</a>
									</div>
								</div>

								<?php 
							}
						}
						
						wp_reset_postdata(); // Сбрасываем $post
						
						?>
					</div>
				</div>
			</div>
  • Вопрос задан
  • 65 просмотров
Подписаться 1 Средний 3 комментария
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы