Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. function listify_cover( $class, $args = array() ) {
  2. $defaults = apply_filters(
  3. 'listify_cover_defaults',
  4. array(
  5. 'images' => false,
  6. 'object_ids' => false,
  7. 'size' => 'large',
  8. )
  9. );
  10. $args = wp_parse_args( $args, $defaults );
  11. $image = false;
  12. $atts = array();
  13.  
  14. global $wp_query;
  15.  
  16. $post = get_post();
  17.  
  18. if ( ( function_exists( 'is_shop' ) && is_shop() ) || is_singular( 'product' ) ) { // WooCommerce shop and product.
  19. $image = wp_get_attachment_image_src( get_post_thumbnail_id( wc_get_page_id( 'shop' ) ), $args['size'] );
  20. } elseif ( is_tax( array( 'product_cat', 'product_tag' ) ) ) { // WooCommerce archive.
  21. $thumbnail_id = get_woocommerce_term_meta( get_queried_object_id(), 'thumbnail_id', true );
  22. $image = wp_get_attachment_image_src( $thumbnail_id, $args['size'] );
  23. } elseif ( ( is_home() && ! in_the_loop() ) ) { // Blog.
  24. $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_option( 'page_for_posts' ) ), $args['size'] );
  25. } elseif ( ! in_the_loop() && is_singular( 'post' ) ) { // Blog post.
  26. $image = array( get_the_post_thumbnail_url( get_post(), $args['size'] ) );
  27. } elseif ( ( ! did_action( 'loop_start' ) && is_archive() ) || ( $args['images'] || $args['object_ids'] ) ) { // Blog archive.
  28. $image = listify_get_cover_from_group( $args );
  29. } elseif ( is_a( $post, 'WP_Post' ) ) { // Single.
  30. if ( '' !== $post->_thumbnail_id ) {
  31. $image = wp_get_attachment_image_src( get_post_thumbnail_id(), $args['size'] );
  32. } elseif ( apply_filters( 'listify_listing_cover_use_gallery_images', false ) && listify_has_integration( 'wp-job-manager' ) ) {
  33. $gallery = Listify_WP_Job_Manager_Gallery::get( $post->ID );
  34.  
  35. if ( $gallery ) {
  36. $args['images'] = $gallery;
  37. $args['post_type'] = 'job_listing';
  38.  
  39. unset( $args['object_ids'] );
  40.  
  41. $image = listify_get_cover_from_group( $args );
  42. }
  43. }
  44. }
  45.  
  46. $image = apply_filters( 'listify_cover_image', $image, $args );
  47.  
  48. if ( ! $image ) {
  49. $class .= ' no-image';
  50.  
  51. return sprintf( 'class="%s"', $class );
  52. }
  53.  
  54. $class .= ' has-image';
  55.  
  56. $atts[] = sprintf( 'style="background-image: url(%s);"', $image[0] );
  57. $atts[] = sprintf( 'class="%s"', $class );
  58.  
  59. return implode( ' ', $atts );
  60.  
  61. <div <?php echo apply_filters( 'listify_cover', 'page-cover' ); ?>>
  62. <div class="page-title cover-wrapper">
  63. <?php woocommerce_page_title(); ?>
  64. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement