Hiển thị tự động Menu danh mục sản phẩm Woocommerce theo từng cấp

5/5 - (1 bình chọn)

Sau đây Biweb hướng dẫn quý khách thiết kế Web bằng WordPress, cách Hiển thị tự động Menu danh mục sản phẩm Woocommerce theo từng cấp như sau

danhmucsanphamwoo

Chèn đoạn code sau vào nơi cần hiển thị Menu

<ul class="web5cmenu2new">
<?php

$taxonomy = 'product_cat';
$orderby = 'name'; 
$show_count = 0; 
$pad_counts = 0; 
$hierarchical = 1; 
$title = ''; 
$empty = 0;

$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);

$all_categories = get_categories( $args );

foreach ($all_categories as $cat) {

if($cat->category_parent == 0) {

$category_id = $cat->term_id;

echo '<div class="web5cmenu2"><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>';

$args2 = array(
'taxonomy' => $taxonomy,
'parent' => $category_id,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);

$sub_cats = get_categories( $args2 );

if($sub_cats) {

echo '<div class="web5cmenuc2sub">';

foreach($sub_cats as $sub_category) {

echo '<li class="sublic2"><div class="menu-item"><a href="'. get_term_link($sub_category->slug, 'product_cat') .'">'. $sub_category->name .'</a></div>';

$args3 = array(
'taxonomy' => $taxonomy,
'parent' => $sub_category->term_id,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);

$sub_cats3 = get_categories( $args3 );

echo '<div class="web5cmenuc3sub">';
if($sub_cats3) {
foreach($sub_cats3 as $sub_category3) {
echo '<div class="menu-item"><a href="'. get_term_link($sub_category3->slug, 'product_cat') .'">'. $sub_category3->name .'</a></div>';
}
}
echo '</div>';


echo '</li>';

}

echo '</div>';
}
echo '</div>';
}


}


?>


</ul>

Tiếp theo hãy CSS làm đẹp cho Menu của bạn theo cách bạn muốn nhé

Dưới dây là Menu mẫu của chúng tôi như ảnh trên

ul.web5cmenu2new {
background: #fff;
border: none;
border-radius: 0;
float: left;
width: 100%;
margin: 0 0 25px 0;
padding: 0;
}
.web5cmenu2 {
margin: 0;
padding: 10px 45px;
position: relative;
float: left;
width: 100%;
font-size: 15px;
text-transform: none;
font-weight: 500;
border-bottom: 1px solid #ebebeb;
}
.web5cmenu2:before {
position: absolute;
left: 13px;
top: 8px;
padding: 0;
width: 22px;
height: 25px;
content: "";
}
.web5cmenu2:first-child:before {
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(2):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(3):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(4):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(5):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(6):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(7):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(8):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(9):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(10):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:nth-child(11):before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}
.web5cmenu2:last-child:before{
background: url(anbiweb-js/images/icon-quat.png) no-repeat center;
}

.woocommerce ul.products li.product .button {
margin-top: 1em;
display: none !important;
}
.block-show .content .title-brand a {
color: #ed6c8b;
text-transform: uppercase;
font-weight: 700;
display: none !important;
}
.web5cmenu2:hover:after {
z-index: 9999;
top: 0;
bottom: 0;
margin: auto;
height: 0;
position: absolute;
content: "";
right: -28px;
border-top: 22px solid transparent;
border-left: 11px solid #ed6c8b;
border-bottom: 22px solid transparent;
border-right: 18px solid transparent;
}
.web5cmenu2:hover {
background: #ed6c8b;
}
:before {
display: inline-block;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}
.web5cmenu2:hover a {
color: #000 !important;
}


.web5cmenu2:last-child {
border: none !important;
}
.web5cmenu2 a:hover, .web5cmenuc2sub li a:hover {
color: #fff !important;
}

.web5cmenu2:hover a, .web5cmenuc2sub li:hover a {
color: #ed6c8b;
}
.web5cmenu2:hover .web5cmenuc2sub a {
color: #ed6c8b;
line-height: 15px;
height: 34px;
padding: 10px 20px;
}
.web5cmenuc2sub li:hover, .web5cmenuc3sub .menu-item:hover {
background: transparent;
}

Chúc bạn thành công!

5/5 - (1 bình chọn)


  1. It’s remarkable for me to have a site, which is useful designed for my knowledge.
    thanks admin

  2. After I initially commented I seem to have clicked on the -Notify me when new comments are added- checkbox and
    from now on each time a comment is added I receive 4 emails with the same comment.
    Perhaps there is an easy method you are able to remove me from
    that service? Thank you!

  3. My brother recommended I would possibly like this blog.
    He was entirely right. This publish truly made my day.
    You can not believe simply how much time I had spent for
    this information! Thanks!

  4. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your
    point. You clearly know what youre talking about, why waste your intelligence on just
    posting videos to your site when you could be giving us
    something informative to read?

  5. Helpful information. Lucky me I discovered your website by chance, and I’m stunned why this twist
    of fate didn’t took place in advance! I bookmarked it.

  6. A motivating discussion is definitely worth comment. I think that you need to write more about this topic, it might not be a taboo subject but typically people do not talk about
    such issues. To the next! Kind regards!!

  7. For the reason that the admin of this website is working, no uncertainty very quickly it will be renowned, due to its feature
    contents.

  8. https://wiki-aero.win/index.php?title=Guarding_Progress:_Critical_Approaches_for_Building_Web-site_Stability_in_Ny_city_66215 viết:

    Way cool! Some extremely valid points! I appreciate you penning this write-up and the
    rest of the site is extremely good.

  9. https://kameronyfjm789.weebly.com/blog/securing-your-organization-important-methods-for-industrial-stability-options-in-the-large-apple viết:

    Hi! Do you use Twitter? I’d like to follow you if that would be ok.
    I’m definitely enjoying your blog and look forward to new posts.

  10. When I initially commented I seem to have clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment.

    Is there a way you are able to remove me from that service?
    Thanks!

  11. Very good article! We are linking to this particularly
    great content on our website. Keep up the great writing.

  12. скачать казино brillx
    https://brillx-kazino.com
    Наше казино стремится предложить лучший игровой опыт для всех игроков, и поэтому мы предлагаем возможность играть как бесплатно, так и на деньги. Если вы новичок и хотите потренироваться перед серьезной игрой, то вас приятно удивят бесплатные режимы игр. Они помогут вам разработать стратегии и привыкнуть к особенностям каждого игрового автомата.Играя на Brillx Казино, вы можете быть уверены в честности и безопасности своих данных. Мы используем передовые технологии для защиты информации наших игроков, так что вы можете сосредоточиться исключительно на игре и наслаждаться процессом без каких-либо сомнений или опасений.

  13. brillx официальный сайт играть онлайн
    https://brillx-kazino.com
    Так что не упустите свой шанс вступить в мир Brillx Казино! Играйте онлайн бесплатно и на деньги в 2023 году, окунувшись в море невероятных эмоций и неожиданных поворотов. Brillx – это не просто игровые аппараты, это источник вдохновения и увлечения. Поднимите ставки и дайте себе шанс на большую победу вместе с нами!Играя на Brillx Казино, вы можете быть уверены в честности и безопасности своих данных. Мы используем передовые технологии для защиты информации наших игроков, так что вы можете сосредоточиться исключительно на игре и наслаждаться процессом без каких-либо сомнений или опасений.

  14. [url=https://teplica-teplourala.ru]Теплицы новгород купить.[/url]
    [url=https://teplica-teplourala.ru]Прямостенные теплицы от производителя цены.[/url]
    [url=https://teplica-teplourala.ru]Теплицы прямостенные от производителя.[/url]

  15. naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *