Last active
July 9, 2021 11:17
-
-
Save Prroffessorr/cad54fdc13e27eea1337d2bdf49665ff to your computer and use it in GitHub Desktop.
Вывод списка категорий с помощью плагина ACF. Настройки поля (Тип поля: Таксономия. Таксономия: Категория. Возвращаемое значение: ID Термина)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Первый вариант с настройкой отображения | |
$args = array( | |
'orderby'=> 'menu_order', | |
'order'=>'ASC', | |
'hide_empty'=> true, | |
'include'=> get_field("main_woo_category"), | |
'parent'=> 0, | |
); | |
$category_products = get_terms( 'product_cat', $args ); | |
if( $category_products ): ?> | |
<div class="row"> | |
<?php | |
foreach($category_products as $element): | |
$woo_cat_id = $element->term_id; ?> | |
<div class="col-md-4"> | |
<a href="<?php echo get_category_link($woo_cat_id); ?>" class="inner"> | |
<img src="<?php echo wp_get_attachment_url(get_woocommerce_term_meta( $woo_cat_id, 'thumbnail_id', true )); ?>" alt="<?php echo get_post_meta(get_woocommerce_term_meta( $woo_cat_id, 'thumbnail_id', true ), '_wp_attachment_image_alt', true); ?>"> | |
<span><strong><b><?php echo get_the_category_by_ID($woo_cat_id); ?></b></strong></span> | |
</a> | |
</div> | |
<?php endforeach; ?> | |
</div> | |
<?php endif; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Обычный вариант без настроек | |
$term_woo_category = get_field('main_woo_category'); | |
if( $term_woo_category ): ?> | |
<div class="row"> | |
<?php foreach( $term_woo_category as $cat_id): ?> | |
<div class="col-md-4"> | |
<a href="<?php echo get_category_link($cat_id); ?>" class="inner"> | |
<img src="<?php echo wp_get_attachment_url(get_woocommerce_term_meta( $cat_id, 'thumbnail_id', true )); ?>" alt="<?php echo get_post_meta(get_woocommerce_term_meta( $woo_cat_id, 'thumbnail_id', true ), '_wp_attachment_image_alt', true); ?>"> | |
<span><strong><b><?php echo get_the_category_by_ID($cat_id); ?></b></strong></span> | |
</a> | |
</div> | |
<?php endforeach; ?> | |
</div> | |
<?php endif; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Третий вариант для комплектсного поля | |
$main_page_sevices_list = get_field('main_page_sevices_list'); | |
if( $main_page_sevices_list ): ?> | |
<div class="row"> | |
<?php foreach( $main_page_sevices_list as $sevices): ?> | |
<div class="col-md-4"> | |
<a href="<?php echo get_the_permalink($sevices["main_page_sevices_href"]); ?>" class="inner"> | |
<img src="<?php echo esc_url($sevices["main_page_sevices_image"]['url']); ?>" alt="<?php echo esc_url($sevices["main_page_sevices_image"]['alt']); ?>"> | |
<span><strong><b><?php echo get_the_title($sevices["main_page_sevices_href"]); ?></b></strong></span> | |
</a> | |
</div> | |
<?php endforeach; ?> | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment