D
D
Dmitry2016-09-26 11:18:42
Node.js
Dmitry, 2016-09-26 11:18:42

How to wrap in a tag?

There is a code

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) );
    }

You need to wrap the li in an a tag to get this structure.
<a>
<li>
<div class="thumbnail">
......
</div>
</li>
</a>

Tell me how to do it, please.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Severus256, 2016-09-20
@severus256

You can try using $stateParams and pass data directly to url when redirecting:
$state.go("/pages", {data: yourData}); at the same time, when the controller is restarted, the data will be stored in data.
More or less like this

D
deadkEEper1, 2016-09-20
@deadkEEper1

Use kveri parameters. Passed in url after "?" in the form key=value & otherKey=otherValue

app.post('/notes', function(req, res){
  var options = body;
  
  var _name = options.name;
  var _age = options.age;

  res.redirect('/page?name=_name&age=_age')
})

app.get('/page', function(req, res){
  var options = req.query;
  
  var name = options.name;
  var age = options.age;

  ....
})

D
Dmitry, 2016-09-26
@losttheory

Made it like this

$html .= '<a href="'.esc_url($link).'"><li>';
$html .= '</li></a>';

Didn't turn around. It turned out like this:
<a></a>
<li>
<a></a>
</li>

O
Optimus, 2016-09-26
Pyan @marrk2

Do you need unique links? And that's just:

$html .= '<a><li>';
$html .= '<li></a>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question