@losttheory

Как обернуть в тег a?

Имеется код
if( $results->have_posts() ){
			$extra_class = '';
			if( isset($results->post_count, $results->found_posts) && $results->found_posts > $results->post_count ){
				$extra_class = 'has-view-all';
			}
			
			$html = '<ul class="'.$extra_class.'">';
			while( $results->have_posts() ){
				$results->the_post();
				$link = get_permalink($post->ID);
				
				$image = '';
				if( $post_type == 'product' ){
					$product = wc_get_product($post->ID);
					$image = $product->get_image();
				}
				else if( has_post_thumbnail($post->ID) ){
					$image = get_the_post_thumbnail($post->ID, 'thumbnail');
				}
				
					$html .= '<li>';
						$html .= '<div class="thumbnail">';
							$html .= '<a href="'.esc_url($link).'">'. $image .'</a>';
						$html .= '</div>';
						$html .= '<div class="meta">';
							$html .= '<a href="'.esc_url($link).'" class="title">'. ts_search_highlight_string($post->post_title, $search_string) .'</a>';
							$html .= '<div class="description">'. ts_the_excerpt_max_words($desc_limit_words, '', true, ' ...', false) .'</div>';
							if( $post_type == 'product' ){
								if( $price_html = $product->get_price_html() ){
									$html .= '<span class="price">'. $price_html .'</span>';
								}
							}
						$html .= '</div>';
					$html .= '</li>';
			}
			$html .= '</ul>';
			
			if( isset($results->post_count, $results->found_posts) && $results->found_posts > $results->post_count ){
				$view_all_text = sprintf( esc_html__('View all %d results', 'gon'), $results->found_posts );
				
				$html .= '<div class="view-all-wrapper">';
					$html .= '<a href="#">'. $view_all_text .'</a>';
				$html .= '</div>';
			}
			
			wp_reset_postdata();
			
			$return = array();
			$return['html'] = $html;
			$return['search_string'] = $search_string;
			die( json_encode($return) );
		}


Требуется li обернуть в тег a, чтобы получить такую структуру.
<a>
<li>
<div class="thumbnail">
......
</div>
</li>
</a>


Подскажите как это сделать, пожалуйста.
  • Вопрос задан
  • 555 просмотров
Решения вопроса 1
@losttheory Автор вопроса
Сделал вот так
$html .= '<a href="'.esc_url($link).'"><li>';
$html .= '</li></a>';


Не обернулась. Получилось так:
<a></a>
<li>
<a></a>
</li>
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
Ссылки уникальные нужны? А то просто:
$html .= '<a><li>';
$html .= '<li></a>';
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы