Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function listify_cover( $class, $args = array() ) {
- $defaults = apply_filters(
- 'listify_cover_defaults',
- array(
- 'images' => false,
- 'object_ids' => false,
- 'size' => 'large',
- )
- );
- $args = wp_parse_args( $args, $defaults );
- $image = false;
- $atts = array();
- global $wp_query;
- $post = get_post();
- if ( ( function_exists( 'is_shop' ) && is_shop() ) || is_singular( 'product' ) ) { // WooCommerce shop and product.
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( wc_get_page_id( 'shop' ) ), $args['size'] );
- } elseif ( is_tax( array( 'product_cat', 'product_tag' ) ) ) { // WooCommerce archive.
- $thumbnail_id = get_woocommerce_term_meta( get_queried_object_id(), 'thumbnail_id', true );
- $image = wp_get_attachment_image_src( $thumbnail_id, $args['size'] );
- } elseif ( ( is_home() && ! in_the_loop() ) ) { // Blog.
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_option( 'page_for_posts' ) ), $args['size'] );
- } elseif ( ! in_the_loop() && is_singular( 'post' ) ) { // Blog post.
- $image = array( get_the_post_thumbnail_url( get_post(), $args['size'] ) );
- } elseif ( ( ! did_action( 'loop_start' ) && is_archive() ) || ( $args['images'] || $args['object_ids'] ) ) { // Blog archive.
- $image = listify_get_cover_from_group( $args );
- } elseif ( is_a( $post, 'WP_Post' ) ) { // Single.
- if ( '' !== $post->_thumbnail_id ) {
- $image = wp_get_attachment_image_src( get_post_thumbnail_id(), $args['size'] );
- } elseif ( apply_filters( 'listify_listing_cover_use_gallery_images', false ) && listify_has_integration( 'wp-job-manager' ) ) {
- $gallery = Listify_WP_Job_Manager_Gallery::get( $post->ID );
- if ( $gallery ) {
- $args['images'] = $gallery;
- $args['post_type'] = 'job_listing';
- unset( $args['object_ids'] );
- $image = listify_get_cover_from_group( $args );
- }
- }
- }
- $image = apply_filters( 'listify_cover_image', $image, $args );
- if ( ! $image ) {
- $class .= ' no-image';
- return sprintf( 'class="%s"', $class );
- }
- $class .= ' has-image';
- $atts[] = sprintf( 'style="background-image: url(%s);"', $image[0] );
- $atts[] = sprintf( 'class="%s"', $class );
- return implode( ' ', $atts );
- <div <?php echo apply_filters( 'listify_cover', 'page-cover' ); ?>>
- <div class="page-title cover-wrapper">
- <?php woocommerce_page_title(); ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement