sahoo 0 ارسال شده در تیر 94 گزارش بازنشر ارسال شده در تیر 94 با سلام به دوستانمشکل این کد چیه؟؟من وقتی دسته بندی رو انتحاب میکنم (مثلا 10تا دسته بندی) فقط یک عدد رو نشون میدهadd_action( 'wp_ajax_multi_cat', 'ajax_action_multi_cat' );add_action( 'wp_ajax_nopriv_multi_cat', 'ajax_action_multi_cat' );if( !function_exists('ajax_action_multi_cat') ) {function ajax_action_multi_cat() {$nonce = $_POST['nonce']; if ( ! wp_verify_nonce( $nonce, 'ajaxed-nonce' ) ) die ( 'Nope!' ); $data = $_POST; $page = intval($data['page']); $paged = ($page) ? $page : 1; ob_start(); $query_args = array( 'paged' => $paged, 'post_type' => 'post', 'posts_per_page' => 5, 'tax_query' => array( array( 'taxonomy' => $data['tax'], 'field' => 'id', 'terms' => $data['term'] ) ), ); $query = new WP_Query($query_args); $response = ''; if ( $query->have_posts() ) { while ($query->have_posts() ) { $query->the_post(); ob_start(); get_template_part( 'content', 'multi_category' ); $response .= ob_get_clean(); } wp_reset_postdata(); } else { $response = 'fail'; } echo $response ; exit;}}if( !function_exists('wpsm_categorizator_shortcode') ) {function wpsm_categorizator_shortcode( $atts, $content = null ) {extract(shortcode_atts(array( 'tax' => 'category', 'exclude' => '', 'include' => '', 'col' => '3' ), $atts)); $taxonomies = array($tax); $args = array( 'orderby' => 'name', 'exclude' => array($exclude), 'include' => array($include), ); $terms = get_terms( $taxonomies, $args );ob_start(); ?> <?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { if ($col == '4') { echo '<div class="col_wrap_fourth">'; } else {echo '<div class="col_wrap_three">'; } $i = 1; foreach ($terms as $term) { $query_args = array( 'post_type' => 'post', 'posts_per_page' => 5, 'tax_query' => array( array( 'taxonomy' => $term->taxonomy, 'field' => 'id', 'terms' => $term->term_id ) ), ); $query = new WP_Query($query_args); if ( $query->have_posts() ) : ?> <div id="directory-<?php echo $term->term_id; ?>" class="multi_cat col_item" data-tax="<?php echo $term->taxonomy; ?>" data-term="<?php echo $term->term_id; ?>"> <div class="multi_cat_header"> <div class="multi_cat_lable"> <?php echo $term->name; ?> </div> </div> <div class="multi_cat_wrap eq_height_post"> <?php while ($query->have_posts() ) : $query->the_post(); get_template_part( 'content', 'multi_category' ); endwhile; wp_reset_postdata(); ?> </div> <div class="cat-pagination multi_cat_header clearfix"> <?php for ($j = 1, $max_count = $query->max_num_pages; $j<= $max_count; $j++) : ?> <?php $active = ($j ===1) ? 'active' : '' ;?> <a class="styled <?php echo $active; ?>" data-paginated="<?php echo $j; ?>"><?php echo $j;?></a> <?php endfor; ?> </div> </div> <?php $i++; endif; } echo '</div>'; } ?><?php$output = ob_get_contents();ob_end_clean();return $output;}add_shortcode('wpsm_categorizator', 'wpsm_categorizator_shortcode');} نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .