HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //home/rassvet-tk.ru/public_html/wp-content/themes/rassvettk/page-home-post.php
<?
	$vid = $_POST['vid_name'];
	$vid = trim( $vid , "/" ); //лишний слеш в конце $_POST['vid_name']
	$otrasl = $_POST['otrasl_name'];
	$offset = $_POST['offset'];
	$numberposts = 20;
	// if($_POST['cat_id'] == 5 && $_POST['cat_id2'] == 19){
	// 	$numberposts = 20;
	// }
	$args = array('numberposts' => 20, 'offset' => $_POST['offset'], 'category' => ''.$_POST['cat_id'].','.$_POST['cat_id2'].'','orderby' => 'date','order' => 'desc', );
	$recent_posts_array = get_posts($args); 
				// $last_podcat;
				// $cat_array = array();	
				$k = 0;	
				$i = 0;	

				$url = wp_make_link_relative(get_permalink()); // c 17 по 80 строку сортировка по алфавиту

				if($args['category'] === '7,' || $args['category'] === '9,' || $args['category'] === '8,' || $args['category'] === '39,' ){

					for ($i = 0; $i < count($recent_posts_array); $i++){

						for ($j = $i; $j < count($recent_posts_array); $j++){

							$str1 = $recent_posts_array[$i] -> post_title;
							$str2 = $recent_posts_array[$j] -> post_title;
							$str1 = mb_strtolower($str1, 'UTF-8');
							$str2 = mb_strtolower($str2, 'UTF-8');
							$str1 = preg_replace('/[^а-я]/iu', '', $str1);
							$str2 = preg_replace('/[^а-я]/iu', '', $str2);									

							$min_len = min(strlen($str1), strlen($str2));

							$result = 0;

							for ($k = 0; $k < $min_len; $k++) {
							    $char1 = ord($str1[$k]);
							    $char2 = ord($str2[$k]);
							    if ($k == $min_len - 1){
							        
							            if ($char1 < $char2) {
							            	$result = 1;
							            	break;
							            } elseif ($char1 > $char2) {
							            	$result = -1;
							            	break;
							            }
							            else {

							            	if (strlen($str1) < strlen($str2)) {
							            	$result = 1;
							            	} elseif (strlen($str1) > strlen($str2)) {
							            	$result = -1;
							            	}
							            }      
							        
							    }
							    elseif ($char1 < $char2) {
							        $result = 1;
							        break;
							    } 
							    elseif ($char1 > $char2) {
							        $result = -1;
							        break;
							    } 
							}


							//$result = strcasecmp($str1, $str2);

							if($result === -1){

								$gap = $recent_posts_array[$i];
								$recent_posts_array[$i] = $recent_posts_array[$j];
								$recent_posts_array[$j] = $gap;
							}

						}
					}

				}  //

				// elseif ($url === "/katalog/marinady/"){

				// 	//$recent_posts_array = array_reverse($recent_posts_array, true);

				// }

				foreach( $recent_posts_array as $post ) : 
						setup_postdata($post);
						$postid = $post -> ID;
						$podcat = get_field('podkategorija_tovara');
						$post_thumbnail_url = get_the_post_thumbnail_url($postid, 'full'); //берем ссылочку
						// if(!in_array($podcat, $cat_array)):
						// 	array_unshift($cat_array, $podcat);
						
				?> 	
								<?if(($_POST['cat_id']) != '' && ($_POST['cat_id2']) != ''  ):?>
									<?if(($_POST['cat_id']) != '5' && ($_POST['cat_id2']) != '19'):?>
											<?if(in_category($_POST['cat_id']) && in_category($_POST['cat_id2'])): $i++;?>
												<?if($i ==1):?><div class="row"><?endif;?>
												 	<div class="col-md-6  col-sm-6 col-xs-12 catalog_list_tovar" style="margin-top:20px;" >
													 	<a href="<?echo(wp_make_link_relative(get_permalink( $recent_post_single )))?>">
														 	<div class="tovar_div_img" style="background:url('<?echo (get_the_post_thumbnail_url($postid,'thumbnail')) ?>') no-repeat; background-size:cover; background-position: center;">
														 	</div>
													 	 <? the_title();?>
													 	</a>
													</div>
												<?if($i == 2): $i=0;?></div><?endif;?>
									<?endif;?>
									<?else:$i++;?>
											<?if($i ==1):?><div class="row"><?endif;?>
												 	<div class="col-md-6  col-sm-6 col-xs-12 catalog_list_tovar" style="margin-top:20px;" ><a href="<?echo(wp_make_link_relative(get_permalink( $recent_post_single )))?>">
												 	<div class="tovar_div_img" style="background:url('<?echo (get_the_post_thumbnail_url($postid,'thumbnail')) ?>') no-repeat; background-size:cover; background-position: center;"></div>
												 	 <? the_title();?>
												 	</a></div>
												<?if($i == 2): $i=0;?></div><?endif;?>
									<?endif;?>		
								<?else: $g++;?>

									<?if($g ==0):?><div class="row"><?endif;?>
										<div class="col-md-6  col-sm-6 col-xs-12 catalog_list_tovar" style="margin-top:20px;" ><a href="<?echo(wp_make_link_relative(get_permalink( $recent_post_single )))?>">
										<div class="tovar_div_img" style="background:url('<?echo (get_the_post_thumbnail_url($postid,'thumbnail')) ?>') no-repeat; background-size:cover; background-position: center;"></div>
									 	<? the_title(); ?>
										 </a>
										 </div>
									<?if($g == 2): $g=0;?></div><?endif;?>
								<?endif;?>		
				<?endforeach;?>
<?php 
$args = array('numberposts' => - 1, 'post_type' => 'post', 
	'meta_query' => array('relation' => 'AND', 
		array('key' => 'otbor_po_vidu', 'value' => $vid, 'compare' => '='), 
		array('key' => 'otbor_po_otraslyam', 'value' => $otrasl, 'compare' => '='),),
);
// query
$the_query = new WP_Query($args);
?>
<?php if ($the_query->have_posts()): ?>
		<?php while ($the_query->have_posts()):
        $the_query->the_post(); ?>
        <div class="row">
        	<div class="col-md-12">
        		<div class="title_desc" data-title='<?the_field('title');?>' data-descr='<?the_field('description'); ?>'></div>
        		
			<?the_content();?>
        	</div>
        </div>	
		<?php endwhile; ?>
<?php endif; ?>