Guest User

Untitled

a guest
Jan 6th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <ul class="product-menu">
  2. <?php
  3. $products = new WP_Query(
  4. $args = array(
  5. 'post_type' => 'product',
  6. 'post_status' => 'publish',
  7. )
  8. );
  9. while ( $products->have_posts() ) {
  10. $products->the_post();
  11. $post_thumbnail_id = get_post_thumbnail_id();
  12. $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
  13. echo
  14. '<li>
  15. <a href="' . the_permalink() . '">
  16. <img src="' . $post_thumbnail_url . '" alt="' . get_the_title() . '">
  17. </a>
  18. </li>';
  19. }
  20. /* Restore original Post Data */
  21. wp_reset_postdata();?>
  22. </ul>
  23.  
  24. <ul class="product-menu">
  25. <?php
  26.  
  27. $args = array(
  28. 'post_type' => 'product',
  29. 'post_status' => 'publish',
  30. )
  31.  
  32. $products = new WP_Query($args);
  33.  
  34. while ( $products->have_posts() ) {
  35. $products->the_post();
  36.  
  37. echo '<li><a href="' . get_the_permalink() . '">';
  38.  
  39. // check if the post has a Post Thumbnail assigned to it.
  40. if ( has_post_thumbnail() ) {
  41. the_post_thumbnail();
  42. }
  43.  
  44. echo '</a></li>';
  45. }
  46. /* Restore original Post Data */
  47. wp_reset_postdata();
  48.  
  49. ?>
  50. </ul>
Add Comment
Please, Sign In to add comment