当前位置: 首页>>代码示例>>PHP>>正文


PHP has_post_thumbnail函数代码示例

本文整理汇总了PHP中has_post_thumbnail函数的典型用法代码示例。如果您正苦于以下问题:PHP has_post_thumbnail函数的具体用法?PHP has_post_thumbnail怎么用?PHP has_post_thumbnail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了has_post_thumbnail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: widget

 function widget($args, $instance)
 {
     global $post;
     extract($args, EXTR_SKIP);
     echo $before_widget;
     $title = empty($instance['title']) ? __('Recent Posts', 'lan-thinkupthemes') : apply_filters('widget_title', $instance['title']);
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     $posts = new WP_Query('orderby=date&posts_per_page=' . $instance['postcount'] . '');
     while ($posts->have_posts()) {
         $posts->the_post();
         // Insert post date if needed.
         if ($instance['postdate'] == 'on') {
             $date_input = '<a href="' . get_permalink() . '" class="date">' . get_the_date('M j, Y') . '</a>';
         }
         // HTML output
         echo '<div class="recent-posts">';
         if (has_post_thumbnail() and $instance['imageswitch'] == 'on') {
             echo '<div class="image">', '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_post_thumbnail($post->ID, array(65, 65)) . '<div class="image-overlay"></div></a>', '</div>', '<div class="main">', '<a href="' . get_permalink() . '">' . get_the_title() . '</a>', $date_input, '</div>';
         } else {
             echo '<div class="main">', '<a href="' . get_permalink() . '">' . get_the_title() . '</a>', $date_input, '</div>';
         }
         echo '</div>';
     }
     wp_reset_query();
     echo $after_widget;
 }
开发者ID:closings,项目名称:closings,代码行数:28,代码来源:recentposts.php

示例2: submenu_items

 /**
  * Add Menu Cart to menu
  * 
  * @return menu items including cart
  */
 public function submenu_items()
 {
     $get_cart = jigoshop_cart::get_cart();
     $submenu_items = '';
     //see jigoshop/widgets/cart.php
     if (count($get_cart) > 0) {
         foreach ($get_cart as $cart_item_key => $values) {
             $_product = $values['data'];
             if ($_product->exists() && $values['quantity'] > 0) {
                 $item_thumbnail = has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : jigoshop_get_image_placeholder('shop_tiny');
                 $item_name = $_product->get_title();
                 // Not used: Displays variations and cart item meta
                 $item_meta = jigoshop_cart::get_item_data($values);
                 $item_quantity = esc_attr($values['quantity']);
                 $item_price = $_product->get_price_html();
                 // Item permalink
                 $item_permalink = esc_attr(get_permalink($_product->id));
                 $submenu_items[] = array('item_thumbnail' => $item_thumbnail, 'item_name' => $item_name, 'item_quantity' => $item_quantity, 'item_price' => $item_price, 'item_permalink' => $item_permalink);
             }
         }
     } else {
         $submenu_items = '';
     }
     return $submenu_items;
 }
开发者ID:Atlas-Solutions-Group,项目名称:wp-menu-cart-pro,代码行数:30,代码来源:wpmenucart-jigoshop-pro.php

示例3: wds_set_media_as_featured_image

/**
 * If a YouTube or Vimeo video is added in the post content, grab its thumbnail and set it as the featured image
 */
function wds_set_media_as_featured_image($post_id, $post)
{
    $content = isset($post->post_content) ? $post->post_content : '';
    // Only check the first 1000 characters of our post.
    $content = substr($content, 0, 800);
    // Props to @rzen for lending his massive brain smarts to help with the regex
    $do_video_thumbnail = isset($post->ID) && !has_post_thumbnail($post_id) && $content && (preg_match('/\\/\\/(www\\.)?youtube\\.com\\/(watch|embed)\\/?(\\?v=)?([a-zA-Z0-9\\-\\_]+)/', $content, $youtube_matches) || preg_match('#https?://(.+\\.)?vimeo\\.com/.*#i', $content, $vimeo_matches));
    if (!$do_video_thumbnail) {
        return update_post_meta($post_id, '_is_video', false);
    }
    $video_thumbnail_url = false;
    $youtube_id = $youtube_matches[4];
    $vimeo_id = preg_replace("/[^0-9]/", "", $vimeo_matches[0]);
    if ($youtube_id) {
        // Check to see if our max-res image exists
        $file_headers = get_headers('http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg');
        $video_thumbnail_url = $file_headers[0] !== 'HTTP/1.0 404 Not Found' ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $youtube_id . '/hqdefault.jpg';
    } elseif ($vimeo_id) {
        $vimeo_data = wp_remote_get('http://www.vimeo.com/api/v2/video/' . intval($vimeo_id) . '.php');
        if (isset($vimeo_data['response']['code']) && '200' == $vimeo_data['response']['code']) {
            $response = unserialize($vimeo_data['body']);
            $video_thumbnail_url = isset($response[0]['thumbnail_large']) ? $response[0]['thumbnail_large'] : false;
        }
    }
    // If we found an image...
    $attachment_id = $video_thumbnail_url && !is_wp_error($video_thumbnail_url) ? wds_ms_media_sideload_image_with_new_filename($video_thumbnail_url, $post_id, sanitize_title(get_the_title())) : 0;
    // If attachment wasn't created, bail
    if (!$attachment_id) {
        return;
    }
    // Woot! we got an image, so set it as the post thumbnail
    set_post_thumbnail($post_id, $attachment_id);
    update_post_meta($post_id, '_is_video', true);
}
开发者ID:Art2u,项目名称:Automatic-Featured-Images-from-Videos,代码行数:37,代码来源:automatic-featured-images-from-videos.php

示例4: widget

    /**
     * Displays the output
     *
     * @param array $args
     * @param array $instance
     * @since Achievements (3.3)
     */
    public function widget($args, $instance)
    {
        $settings = $this->parse_settings($instance);
        $settings['post_id'] = absint(apply_filters('dpa_featured_achievement_post_id', $settings['post_id'], $instance, $this->id_base));
        // Get the specified achievement
        $achievement = get_posts(array('no_found_rows' => true, 'numberposts' => 1, 'p' => $settings['post_id'], 'post_status' => 'publish', 'post_type' => dpa_get_achievement_post_type(), 'suppress_filters' => false));
        // Bail if it doesn't exist
        if (empty($achievement)) {
            return;
        }
        $achievement = array_shift($achievement);
        $title = dpa_get_achievement_title($achievement->ID);
        echo $args['before_widget'];
        echo $args['before_title'] . $title . $args['after_title'];
        if (has_post_thumbnail($achievement->ID)) {
            ?>
			<a href="<?php 
            dpa_achievement_permalink($achievement->ID);
            ?>
"><?php 
            echo get_the_post_thumbnail($achievement->ID, 'thumbnail', array('alt' => $title));
            ?>
</a>
		<?php 
        }
        dpa_achievement_excerpt($settings['post_id']);
        echo $args['after_widget'];
    }
开发者ID:rlybbert,项目名称:achievements,代码行数:35,代码来源:class-dpa-featured-achievement-widget.php

示例5: image_cpt_shortcode

function image_cpt_shortcode($attr)
{
    if ($attr['page'] <= 10) {
        $per_page['page'] = $attr['page'];
    } else {
        $per_page['page'] = 10;
    }
    $output = '<h2 class="winner-title">Hall of Winners</h2><h3 class="winner-subtitle">Congratulations to all of our winners</h3>';
    $args = array('post_type' => 'image_post_type', 'posts_per_page' => $per_page['page']);
    $loop = new WP_query($args);
    if ($loop->have_posts()) {
        while ($loop->have_posts()) {
            $loop->the_post();
            $output .= '<div class="winner-div"><h3>';
            $output .= get_the_title();
            $output .= '</h3>';
            if (has_post_thumbnail()) {
                // check if the post has a post thumbnail assigned to it.
                $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($loop->ID), 'full');
                $url = $thumb['0'];
                $output .= '<img src="' . $url . '"/>';
            }
            $output .= '</div>';
        }
    } else {
        // if no content, include the "no posts found" template.
        get_template_part('content', 'none');
    }
    return $output;
}
开发者ID:Shane-McCarthy,项目名称:wordpress-custom-theme,代码行数:30,代码来源:functions.php

示例6: widget

    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        $number = $instance['number'];
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
		<div class="recent-works-items clearfix">
		<?php 
        $args = array('post_type' => 'evolve_portfolio', 'posts_per_page' => $number, 'has_password' => false);
        $portfolio = new WP_Query($args);
        if ($portfolio->have_posts()) {
            ?>
		<?php 
            while ($portfolio->have_posts()) {
                $portfolio->the_post();
                ?>
		<?php 
                if (has_post_thumbnail()) {
                    ?>
		<?php 
                    $link_target = "";
                    $url_check = get_post_meta(get_the_ID(), 'pyre_link_icon_url', true);
                    if (!empty($url_check)) {
                        $new_permalink = get_post_meta(get_the_ID(), 'pyre_link_icon_url', true);
                        if (get_post_meta(get_the_ID(), 'pyre_link_icon_target', true) == "yes") {
                            $link_target = ' target="_blank"';
                        }
                    } else {
                        $new_permalink = get_permalink();
                    }
                    ?>
		<a href="<?php 
                    echo $new_permalink;
                    ?>
"<?php 
                    echo $link_target;
                    ?>
 title="<?php 
                    the_title();
                    ?>
">
			<?php 
                    the_post_thumbnail('recent-works-thumbnail');
                    ?>
		</a>
		<?php 
                }
            }
        }
        wp_reset_query();
        ?>
		</div>

		<?php 
        echo $after_widget;
    }
开发者ID:berniecultess,项目名称:infirev,代码行数:60,代码来源:recent-works-widget.php

示例7: ac_render_ac_easy_slideshow

function ac_render_ac_easy_slideshow($full_width = false, $type = 'royalslider')
{
    // We need to build an array of posts to pass through to the RoyalSlider function
    $posts = array();
    // Should we include the featured image?
    if (has_post_thumbnail() && ac_get_meta('include_featured_image') == 1) {
        $posts[] = get_post(get_post_thumbnail_id());
    }
    // Get the images to use
    $images = ac_get_meta('images', array('type' => 'image_advanced'));
    // Add them to the slides
    foreach ($images as $image) {
        // Add to our slides
        $posts[] = get_post($image['ID']);
    }
    $args = array('slider_style' => 'no-caption', 'slider_size' => 'square', 'class' => 'ac_easy_slider');
    if ($full_width) {
        $args['full_width'] = true;
    }
    // Render the slideshow
    if (count($posts)) {
        if ($type == 'royalslider') {
            echo ac_render_posts_slideshow($args, $posts);
        } else {
            echo ac_render_slick_carousel($args, $posts);
        }
        return true;
    }
    return false;
}
开发者ID:Jhorton4,项目名称:Bohldfeys_Portfolio,代码行数:30,代码来源:functions.slideshows.php

示例8: oxy_shortcode_recent

function oxy_shortcode_recent($atts, $content = '')
{
    // setup options
    extract(shortcode_atts(array('count' => 4, 'categories' => null, 'authors' => null, 'post_formats' => null, 'titles' => 'show'), $atts));
    $categories = null === $categories ? null : explode(',', $categories);
    $authors = null === $authors ? null : explode(',', $authors);
    $post_formats = null === $post_formats ? null : explode(',', $post_formats);
    $posts = oxy_get_recent_posts($count, $categories, $authors, $post_formats);
    $output = '';
    if (!empty($posts)) {
        $output .= '[raw]<ul class="oxyrecentposts">';
        global $post;
        foreach ($posts as $post) {
            setup_postdata($post);
            $output .= '<li>';
            $output .= '<a href="' . get_permalink() . '" class="recent-feature" >';
            if (has_post_thumbnail($post->ID)) {
                $output .= get_the_post_thumbnail($post->ID, array(64, 64), array('title' => $post->post_title, 'alt' => $post->post_title));
            } else {
                // $output .= oxy_theme_icon( oxy_get_post_icon( $post->ID ), 'span' );
            }
            $output .= '</a>';
            if ('show' == $titles) {
                $output .= '<h5>' . get_the_title($post->ID) . '</h5>';
                $output .= '<p>' . get_the_date() . '</p>';
            }
            $output .= '</li>';
        }
        $output .= '</ul>[/raw]';
    }
    // reset post data
    wp_reset_postdata();
    return $output;
}
开发者ID:vanie3,项目名称:appland,代码行数:34,代码来源:shortcodes.php

示例9: get_image

 /**
  * Get post image
  * @since  1.0.0
  */
 public function get_image($link = 'link')
 {
     global $post;
     $post_type = get_post_type($post->ID);
     if (!post_type_supports($post_type, 'thumbnail')) {
         return;
     }
     if (!has_post_thumbnail()) {
         return;
     }
     $post_meta = Cherry_Services_Template_Callbacks::setup_meta();
     if (isset($post_meta['show_thumb']) && 'no' == $post_meta['show_thumb']) {
         return;
     }
     if ('unlink' == $link) {
         $format = '<figure class="cherry-services_thumb">%1$s</figure>';
     } else {
         $format = '<figure class="cherry-services_thumb"><a href="%2$s">%1$s</a></figure>';
     }
     $size = $this->atts['size'];
     if (is_integer($size)) {
         $size = array($size, $size);
     } elseif (!is_string($size)) {
         $size = 'thumbnail';
     }
     $image = get_the_post_thumbnail($post->ID, $size, array('alt' => get_the_title()));
     return sprintf($format, $image, get_permalink());
 }
开发者ID:roberto-alarcon,项目名称:Neuroglobal,代码行数:32,代码来源:class-cherry-services-template-callbacks.php

示例10: widget

 /**
  * Widget
  * Display the widget in the sidebar
  * Save output to the cache if empty
  *
  * @param  array  sidebar arguments
  * @param  array  instance
  */
 public function widget($args, $instance)
 {
     // Hide widget if page is the cart or checkout
     if (is_cart() || is_checkout()) {
         return false;
     }
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Cart', 'fflcommerce'), $instance, $this->id_base);
     // Print the widget wrapper & title
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     // Get the contents of the cart
     $cart_contents = fflcommerce_cart::$cart_contents;
     // If there are items in the cart print out a list of products
     if (!empty($cart_contents)) {
         // Open the list
         echo '<ul class="cart_list">';
         foreach ($cart_contents as $key => $value) {
             // Get product instance
             $_product = $value['data'];
             if ($_product->exists() && $value['quantity'] > 0) {
                 echo '<li>';
                 // Print the product image & title with a link to the permalink
                 echo '<a href="' . esc_attr(get_permalink($_product->id)) . '" title="' . esc_attr($_product->get_title()) . '">';
                 // Print the product thumbnail image if exists else display placeholder
                 echo has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
                 // Print the product title
                 echo '<span class="js_widget_product_title">' . $_product->get_title() . '</span>';
                 echo '</a>';
                 // Displays variations and cart item meta
                 echo fflcommerce_cart::get_item_data($value);
                 // Print the quantity & price per product
                 echo '<span class="js_widget_product_price">' . $value['quantity'] . ' &times; ' . $_product->get_price_html() . '</span>';
                 echo '</li>';
             }
         }
         echo '</ul>';
         // Close the list
         // Print the cart total
         echo '<p class="total"><strong>';
         echo __('Subtotal', 'fflcommerce');
         echo ':</strong> ' . fflcommerce_price($this->total_cart_items());
         echo '</p>';
         do_action('fflcommerce_widget_cart_before_buttons');
         // Print view cart & checkout buttons
         $view_cart_button_label = isset($instance['view_cart_button']) ? $instance['view_cart_button'] : __('View Cart &rarr;', 'fflcommerce');
         $checkout_button_label = isset($instance['checkout_button']) ? $instance['checkout_button'] : __('Checkout &rarr;', 'fflcommerce');
         echo '<p class="buttons">';
         echo '<a href="' . esc_attr(fflcommerce_cart::get_cart_url()) . '" class="button">' . __($view_cart_button_label, 'fflcommerce') . '</a>';
         echo '<a href="' . esc_attr(fflcommerce_cart::get_checkout_url()) . '" class="button checkout">' . __($checkout_button_label, 'fflcommerce') . '</a>';
         echo '</p>';
     } else {
         echo '<span class="empty">' . __('No products in the cart.', 'fflcommerce') . '</span>';
     }
     // Print closing widget wrapper
     echo $after_widget;
 }
开发者ID:barnent1,项目名称:fflcommerce,代码行数:68,代码来源:cart.php

示例11: getImageByPost

function getImageByPost($post)
{
    $cate = get_the_category();
    //echo $cate[0]->cat_ID;
    //$post->post_parent->term_id
    if (has_post_thumbnail($post->ID)) {
        $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
        $image = $image[0];
        return $image;
    } elseif (strlen($catImageUrl = getCategoryImage($cate[0]->cat_ID)) > 0) {
        return $catImageUrl;
    } elseif (strlen(getFirstImage($post->ID)) > 0) {
        $image = getFirstImage($post->ID);
        return $image;
    } else {
        $theme = get_option('themes');
        if ($theme == '10') {
            return get_stylesheet_directory_uri() . '/asset/img/themes/post-default10.jpg';
            // TODO 常量化
        } elseif ($theme == 11) {
            return get_stylesheet_directory_uri() . '/asset/img/themes/post-default11.jpg';
        } elseif ($theme == 12) {
            return get_stylesheet_directory_uri() . '/asset/img/themes/post-default12.jpg';
        } else {
            return get_stylesheet_directory_uri() . '/asset/img/themes/post-default10.jpg';
            // TODO
        }
    }
}
开发者ID:cjhgithub,项目名称:ctheme,代码行数:29,代码来源:post_list.php

示例12: get_tour_info

function get_tour_info()
{
    $tourinfo = array();
    $tour_ID = get_the_ID();
    $tour_title = get_the_title();
    $tour_feat_image_url = get_no_img_url();
    if (has_post_thumbnail()) {
        $tour_feat_image_url = wp_get_attachment_url(get_post_thumbnail_id());
    }
    $tour_excerpt = get_the_excerpt();
    $tour_post_link = get_permalink($tour_ID);
    $tour_departure = get_location_ID(get_post_meta($tour_ID, 'tour_departure', true));
    $tour_arrival = get_location_ID(get_post_meta($tour_ID, 'tour_arrival', true));
    $tour_price = get_post_meta($tour_ID, 'tour_price', true);
    $tour_price_discount = get_post_meta($tour_ID, 'tour_price_discount', true);
    $tour_start = get_post_meta($tour_ID, 'tour_start', true);
    $tour_end = get_post_meta($tour_ID, 'tour_end', true);
    $tour_days = get_post_meta($tour_ID, 'tour_days', true);
    $tourinfo['tour_ID'] = $tour_ID;
    $tourinfo['tour_title'] = $tour_title;
    $tourinfo['tour_feat_image_url'] = $tour_feat_image_url;
    $tourinfo['tour_excerpt'] = $tour_excerpt;
    $tourinfo['tour_post_link'] = $tour_post_link;
    $tourinfo['tour_departure'] = $tour_departure;
    $tourinfo['tour_arrival'] = $tour_arrival;
    $tourinfo['tour_price'] = $tour_price;
    $tourinfo['tour_price_discount'] = $tour_price_discount;
    $tourinfo['tour_start'] = $tour_start;
    $tourinfo['tour_end'] = $tour_end;
    $tourinfo['tour_days'] = $tour_days;
    return $tourinfo;
}
开发者ID:KennyNguyen88,项目名称:ndt-hangdong,代码行数:32,代码来源:functions.php

示例13: ctc_location_columns_content

/**
 * Change location list column content
 *
 * @since 0.9
 * @param string $column Column being worked on
 */
function ctc_location_columns_content($column)
{
    global $post;
    switch ($column) {
        // Thumbnail
        case 'ctc_location_thumbnail':
            if (has_post_thumbnail()) {
                echo '<a href="' . get_edit_post_link($post->ID) . '">' . get_the_post_thumbnail($post->ID, array(80, 80)) . '</a>';
            }
            break;
            // Address
        // Address
        case 'ctc_location_address':
            echo nl2br(strip_tags(get_post_meta($post->ID, '_ctc_location_address', true)));
            break;
            // Times
        // Times
        case 'ctc_location_times':
            echo nl2br(strip_tags(get_post_meta($post->ID, '_ctc_location_times', true)));
            break;
            // Order
        // Order
        case 'ctc_location_order':
            echo isset($post->menu_order) ? $post->menu_order : '';
            break;
    }
}
开发者ID:pmsteil,项目名称:church-theme-content,代码行数:33,代码来源:location-fields.php

示例14: _esc_get_the_image

/**
 * Function to get the image
 *
 * @since		0.1
 * @updated	0.1.3 - Added wp_cache_set()
 * @updated 	0.1.9 - fixed persistent cache per post_id
 * @ref			http://www.ethitter.com/slides/wcmia-caching-scaling-2012-02-18/#slide-11
 */
function _esc_get_the_image($post_id = false)
{
    $post_id = (int) $post_id;
    $cache_key = "featured_image_post_id-{$post_id}-_thumbnail";
    $cache = wp_cache_get($cache_key, null);
    if (!is_array($cache)) {
        $cache = array();
    }
    if (!array_key_exists($cache_key, $cache)) {
        if (empty($cache) || !is_string($cache)) {
            $output = '';
            if (has_post_thumbnail($post_id)) {
                $image_array = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), array(36, 32));
                if (is_array($image_array) && is_string($image_array[0])) {
                    $output = $image_array[0];
                }
            }
            if (empty($output)) {
                //$output = plugins_url( 'images/default.png', __FILE__ );
                $output = apply_filters('featured_image_column_default_image', $output);
            }
            $output = esc_url($output);
            $cache[$cache_key] = $output;
            wp_cache_set($cache_key, $cache, null, 60 * 60 * 24);
        }
    }
    // Make sure we're returning the cached image HT: https://wordpress.org/support/topic/do-not-display-image-from-cache?replies=1#post-6773703
    return isset($cache[$cache_key]) ? $cache[$cache_key] : $output;
}
开发者ID:jaiweb,项目名称:esolutions-wp-base,代码行数:37,代码来源:miscelanious.php

示例15: kobu_post_entry_classes

 function kobu_post_entry_classes($classes)
 {
     // Post Data
     global $post, $wpex_count;
     $post_id = $post->ID;
     $post_type = get_post_type($post_id);
     // Do nothing for slides
     if ($post_type == 'slides') {
         return $classes;
     }
     // Search results
     if (is_search()) {
         $classes[] = 'search-entry';
         if (!has_post_thumbnail()) {
             $classes[] = 'no-featured-image';
         }
         return $classes;
     }
     // Custom class for non standard post types
     if ($post_type !== 'post') {
         $classes[] = $post_type . '-entry';
     }
     // Counter
     if ($wpex_count) {
         $classes[] = 'count-' . $wpex_count;
     }
     // Return classes
     return $classes;
 }
开发者ID:kobuagency,项目名称:wp-kobu-starter,代码行数:29,代码来源:post-classes.php


注:本文中的has_post_thumbnail函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。