logo помогаю бизнесу зарабатывать больше.
Связаться
Введите название услуги:

Выводим категории custom post type

16 мая 2023 в 16:25 Wordpress

Код

<?php
// List of categories of custom taxonomy genre

$args = array(
'type'                     => 'gotovie-okna',
     'show_option_all'    => '',
    'container'           => false,
'orderby'            => 'parent',
'order'              => 'ASC',
    'hide_empty'         => 0,
    'use_desc_for_title' => 0,
    'hierarchical'       => 1,
    'number'             => null,
    'echo'               => 1,
    'depth'              => -1,
    'taxonomy'           => 'tipy-okon',
    'show_count' => 1,
 'child_of' => $this_category->cat_ID,
            'walker' => new Custom_Walker_Category(),
);
?>

<ul>
<?php wp_list_categories( $args ); ?>
</ul>

Рабочий вариант 2 :

<div class="random-okna-listing">
<?php

    $args = array(
             'post_type'        => 'gotovie-okna',
		'orderby' => 'rand', 
		'posts_per_page' => '18'
    );
    query_posts( $args );
	
 echo '<div class="ranrom-listing-slider">';
		
    while ( have_posts() ) : the_post(); 

        global $post;

	?>
<div class="random-okna-listing-item">
<a href="<?php the_permalink();?>"><?php if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/placeholder.jpg" alt="" />
<?php } ?>
</a>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<div class="meta">
Цена: от 1500 руб.
</div> 
</div>	
	<?php
endwhile;

// Reset Post Data
wp_reset_postdata();
	
	 echo '</div>';
	?>
</div>

В функции

class Custom_Walker_Category extends Walker_Category {

        function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
                extract($args);
                $cat_name = esc_attr( $category->name );
                $cat_name = apply_filters( 'list_cats', $cat_name, $category );
                $link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
                if ( $use_desc_for_title == 0 || empty($category->description) )
                        $link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
                else
                        $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
                $link .= '>';
                $link .= $cat_name . '</a>';
                if ( !empty($feed_image) || !empty($feed) ) {
                        $link .= ' ';
                        if ( empty($feed_image) )
                                $link .= '(';
                        $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) ) . '"';
                        if ( empty($feed) ) {
                                $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
                        } else {
                                $title = ' title="' . $feed . '"';
                                $alt = ' alt="' . $feed . '"';
                                $name = $feed;
                                $link .= $title;
                        }
                        $link .= '>';
                        if ( empty($feed_image) )
                                $link .= $name;
                        else
                                $link .= "<img src='$feed_image'$alt$title" . ' />';
                        $link .= '</a>';
                        if ( empty($feed_image) )
                                $link .= ')';
                }
                if ( !empty($show_count) )
                        $link .= ' (' . intval($category->count) . ')';
                if ( 'list' == $args['style'] ) {
                        $output .= "\t<li";
                        $class = 'cat-item cat-item-' . $category->term_id;


                        // YOUR CUSTOM CLASS
                       

                        if ( !empty($current_category) ) {
                                $_current_category = get_term( $current_category, $category->taxonomy );
                                if ( $category->term_id == $current_category )
                                        $class .=  ' current-cat';
                                elseif ( $category->term_id == $_current_category->parent )
                                        $class .=  ' current-cat-parent';
                        }
                        $output .=  ' class="' . $class . '"';
                        $output .= ">$link\n";
                } else {
                        $output .= "\t$link<br />\n";
                }
        } // function start_el

} // class Custom_Walker_Category

 

Похожие статьи

Оставить заявку
По любым вопросам пишите мне в мессенджеры .
Написать в WhatsApp
+7 (925) 444-48-89
Написать в Telegram
@max_webs
Ваша цена
Предложите свою цена за товар или услугу. Пишите мне в мессенджеры или оставьте заявку в данной форме.
Написать в WhatsApp
+7 (925) 444-48-89
Написать в Telegram
@max_webs
[contact-form-7 id="22192" title="Универсальная форма"]
[contact-form-7 id="114828" title="Рассчитать стоимость"]