وب کمپ

مطالب مفید در حوزه طراحی سایت، وردپرس، برنامه نویسی، سئو و دیجیتال مارکتینگ

وب کمپ

مطالب مفید در حوزه طراحی سایت، وردپرس، برنامه نویسی، سئو و دیجیتال مارکتینگ

در این وبلاگ مطالب مفید و مختلفی برای طراحان سایت، وردپرس کاران، برنامه نویسان و سئو کاران ارائه میشود، مطالب این وب سایت بعضا اختصاصی و بعضا هم از سایر وب سایت ها منتشر میشود، و سعی شده است مطالب ناب و به درد بخور جمع آوری شود.
با تشکر، وب کمپ

نویسندگان

سلام به دوستان عزیر

با این کد می توانید دسته بندی های ووکامرس را بصورت لیست سه سطحی نمایش دهید. در انتهای کد هام هم بر چسب های ووکامرس رو نشون میده، بی شک دیدن یک لیست کامل از دسته بندی های و تگ های ووکامرس میتونه به کنترل بهتر آنها کمک کند.

<?php
/*
Template Name: Woocommerce-category-list
*/
echo '<link rel="stylesheet" href="https://laramiss.com/wp-content/themes/woodmart-child/rtl.css" type="text/css" media="screen" />';
echo"
<style>
span.pro-count {
    font-size: 11px;
    font-weight: 400;
}
.box {
padding: 20px;
    text-align: right;
    font-family: IRANSans;
    direction: rtl;
    line-height: 24px;
    margin: 1%;
    border: 1px solid #d1d1d1ad;
}
ul , ol{
    margin: 0;
    padding: 0;
    padding-right: 20px;
}
.box-2 {
    width: 16%;
    float: right;
}
a:link { text-decoration: none; }
</style>
";

  $taxonomy     = 'product_cat';
  $orderby      = 'name';  
  $show_count   = 0;      // 1 for yes, 0 for no
  $pad_counts   = 0;      // 1 for yes, 0 for no
  $hierarchical = 1;      // 1 for yes, 0 for no  
  $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="box" style="clear: both;"><div style="border-bottom: 2px solid #9d80a9; padding: 10px; margin-bottom: 10px; background: #f3f3f3;"><a style="font-size: 21px; font-weight: 800; color: #606060; padding-bottom: 8; margin-bottom: 15px;" target="_blank" href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a><span class="pro-count"> (' .   $cat->count  . ')</span></div>';

        $args2 = array(
                'taxonomy'     => $taxonomy,
                'child_of'     => 0,
                '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) {
            foreach($sub_cats as $sub_category) {
               // echo  $sub_category->name ;
                 echo '<div class="box-2"><a style="font-size:17px; font-weight: 600; color: #424242; line-height: 30px;" target="_blank" href="'. get_term_link($sub_category->slug, 'product_cat') .'">'. $sub_category->name .'</a><span class="pro-count"> (' .   $sub_category->count  . ')</span>';
                 $category_id3 = $sub_category->term_id; 
                 $args3 = array(
                'taxonomy'     => $taxonomy,
                'child_of'     => 0,
                'parent'       => $category_id3,
                'orderby'      => $orderby,
                'show_count'   => $show_count,
                'pad_counts'   => $pad_counts,
                'hierarchical' => $hierarchical,
                'title_li'     => $title,
                'hide_empty'   => $empty
        );
                 $sub_cats3 = get_categories( $args3 );
                        if($sub_cats3) {
                            echo "<ol>";
                        foreach($sub_cats3 as $sub_category3) {
                           // echo  $sub_category->name ;
                             echo '<li><a style="font-size:14px; font-weight: 500;" target="_blank" href="'. get_term_link($sub_category3->slug, 'product_cat') .'">'. $sub_category3->name .'</a><span class="pro-count"> (' .   $sub_category3->count  . ')</span></li>';
                                    $category_id4 = $sub_category3->term_id; 
                 $args4 = array(
                'taxonomy'     => $taxonomy,
                'child_of'     => 0,
                'parent'       => $category_id4,
                'orderby'      => $orderby,
                'show_count'   => $show_count,
                'pad_counts'   => $pad_counts,
                'hierarchical' => $hierarchical,
                'title_li'     => $title,
                'hide_empty'   => $empty
        );
                 $sub_cats4 = get_categories( $args4 );
                        if($sub_cats4) {
                            echo "<ul>";
                            foreach($sub_cats4 as $sub_category4) {
                             echo '<li><a style="font-size:13px; font-weight: 300;" target="_blank" href="'. get_term_link($sub_category4->slug, 'product_cat') .'">'. $sub_category4->name .'</a><span class="pro-count"> (' .   $sub_category4->count  . ')</span></li>';
                            }
                            echo "</ul>";
                        }
                        // $sub_cats4
                        }  
                        echo "</ol>";
                        }
                        echo "</div>";
         
            }   

        }
        echo "<div style='clear: both;'></div></div>";
    }
}
?>
<?php $terms = get_terms(array('taxonomy' => 'product_tag', 'hide_empty' => false)); ?>
<div class="product-tags">
<?php foreach ( $terms as $term ) { ?>
    <a href="<?php echo get_term_link( $term->term_id, 'product_tag' ); ?> " rel="tag" target="_blank"><?php echo $term->name; ?></a>
<?php } ?>
</div>

 

نظرات  (۰)

هیچ نظری هنوز ثبت نشده است

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی