本文整理汇总了PHP中Jetpack_PostImages::get_image方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack_PostImages::get_image方法的具体用法?PHP Jetpack_PostImages::get_image怎么用?PHP Jetpack_PostImages::get_image使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jetpack_PostImages
的用法示例。
在下文中一共展示了Jetpack_PostImages::get_image方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: colorposts_get_post_image
/**
* Get an image from a post
*
* @uses Jetpack_PostImages::get_image( $post_id ) to get the source of an image in a post, apply_filters()
*
* @since 1.0
*
* @return string $the_image the image source
*/
function colorposts_get_post_image()
{
$post_id = get_the_ID();
if (class_exists('Jetpack_PostImages')) {
$the_image = Jetpack_PostImages::get_image($post_id);
if (!empty($the_image['src'])) {
$the_image = $the_image['src'];
} else {
$the_image = apply_filters('jetpack_open_graph_image_default', "http://wordpress.com/i/blank.jpg");
}
}
$the_image = apply_filters('colorposts_image_output', $the_image);
return esc_url($the_image);
}
示例2: wpcom_amp_add_image_to_metadata
function wpcom_amp_add_image_to_metadata($metadata, $post)
{
if (!class_exists('Jetpack_PostImages')) {
return wpcom_amp_add_fallback_image_to_metadata($metadata);
}
$image = Jetpack_PostImages::get_image($post->ID, array('fallback_to_avatars' => true, 'avatar_size' => 200, 'from_thumbnail' => false, 'from_attachment' => false));
if (empty($image)) {
return wpcom_amp_add_fallback_image_to_metadata($metadata);
}
if (!isset($image['src_width'])) {
$dimensions = wpcom_amp_getimagesize($image['src']);
if ($dimensions) {
$image['src_width'] = $dimensions[0];
$image['src_height'] = $dimensions[1];
}
}
$metadata['image'] = array('@type' => 'ImageObject', 'url' => $image['src'], 'width' => $image['src_width'], 'height' => $image['src_height']);
return $metadata;
}
示例3: widget
function widget($args, $instance)
{
$title = isset($instance['title']) ? $instance['title'] : false;
if (false === $title) {
$title = $this->default_title;
}
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters('widget_title', $title);
$count = isset($instance['count']) ? (int) $instance['count'] : false;
if ($count < 1 || 10 < $count) {
$count = 10;
}
/**
* Control the number of displayed posts.
*
* @since 3.3.0
*
* @param string $count Number of Posts displayed in the Top Posts widget. Default is 10.
*/
$count = apply_filters('jetpack_top_posts_widget_count', $count);
$types = isset($instance['types']) ? (array) $instance['types'] : array('post', 'page');
if (isset($instance['display']) && in_array($instance['display'], array('grid', 'list', 'text'))) {
$display = $instance['display'];
} else {
$display = 'text';
}
if ('text' != $display) {
$get_image_options = array('fallback_to_avatars' => true, 'gravatar_default' => apply_filters('jetpack_static_url', set_url_scheme('http://en.wordpress.com/i/logo/white-gray-80.png')));
if ('grid' == $display) {
$get_image_options['avatar_size'] = 200;
} else {
$get_image_options['avatar_size'] = 40;
}
/**
* Top Posts Widget Image options.
*
* @since 1.8.0
*
* @param array $get_image_options {
* Array of Image options.
* @type bool true Should we default to Gravatars when no image is found? Default is true.
* @type string $gravatar_default Default Image URL if no Gravatar is found.
* @type int $avatar_size Default Image size.
* }
*/
$get_image_options = apply_filters('jetpack_top_posts_widget_image_options', $get_image_options);
}
$posts = $this->get_by_views($count);
// Filter the returned posts. Remove all posts that do not match the chosen Post Types.
if (isset($types)) {
foreach ($posts as $k => $post) {
if (!in_array($post['post_type'], $types)) {
unset($posts[$k]);
}
}
}
if (!$posts) {
$posts = $this->get_fallback_posts();
}
echo $args['before_widget'];
if (!empty($title)) {
echo $args['before_title'] . $title . $args['after_title'];
}
if (!$posts) {
if (current_user_can('edit_theme_options')) {
echo '<p>' . sprintf(__('There are no posts to display. <a href="%s">Want more traffic?</a>', 'jetpack'), 'http://en.support.wordpress.com/getting-more-site-traffic/') . '</p>';
}
echo $args['after_widget'];
return;
}
switch ($display) {
case 'list':
case 'grid':
wp_enqueue_style('widget-grid-and-list');
foreach ($posts as &$post) {
$image = Jetpack_PostImages::get_image($post['post_id'], array('fallback_to_avatars' => true));
$post['image'] = $image['src'];
if ('blavatar' != $image['from'] && 'gravatar' != $image['from']) {
$size = (int) $get_image_options['avatar_size'];
$post['image'] = jetpack_photon_url($post['image'], array('resize' => "{$size},{$size}"));
}
}
unset($post);
if ('grid' == $display) {
echo "<div class='widgets-grid-layout no-grav'>\n";
foreach ($posts as $post) {
?>
<div class="widget-grid-view-image">
<?php
/**
* Fires before each Top Post result, inside <li>.
*
* @since 3.2.0
*
* @param string $post['post_id'] Post ID.
*/
do_action('jetpack_widget_top_posts_before_post', $post['post_id']);
?>
<a href="<?php
echo esc_url($post['permalink']);
//.........这里部分代码省略.........
示例4: get_image
public function get_image($post)
{
if (class_exists('Jetpack_PostImages')) {
$image = Jetpack_PostImages::get_image($post->ID, array('fallback_to_avatars' => true));
if (!empty($image)) {
return $image['src'];
}
}
/**
* Filters the default image used by the Pinterest Pin It share button.
*
* @module sharedaddy
*
* @since 3.6.0
*
* @param string $url Default image URL.
*/
return apply_filters('jetpack_sharing_pinterest_default_image', 'https://s0.wp.com/i/blank.jpg');
}
示例5: widget
function widget($args, $instance)
{
$title = isset($instance['title']) ? $instance['title'] : false;
if (false === $title) {
$title = $this->default_title;
}
$title = apply_filters('widget_title', $title);
$count = isset($instance['count']) ? (int) $instance['count'] : false;
if ($count < 1 || 20 < $count) {
$count = 10;
}
if (isset($instance['display']) && in_array($instance['display'], array('grid', 'list', 'text'))) {
$display = $instance['display'];
} else {
$display = 'text';
}
if ('text' != $display) {
$get_image_options = array('fallback_to_avatars' => true, 'gravatar_default' => apply_filters('jetpack_static_url', is_ssl() ? 'https' : 'http' . '://en.wordpress.com/i/logo/white-gray-80.png'));
if ('grid' == $display) {
if ($count % 2 != 0) {
$count++;
}
$get_image_options['avatar_size'] = 200;
} else {
$get_image_options['avatar_size'] = 40;
}
$get_image_options = apply_filters('jetpack_top_posts_widget_image_options', $get_image_options);
}
$posts = $this->get_by_views($count);
if (!$posts) {
$posts = $this->get_fallback_posts();
}
echo $args['before_widget'];
if (!empty($title)) {
echo $args['before_title'] . $title . $args['after_title'];
}
if (!$posts) {
if (current_user_can('edit_theme_options')) {
echo '<p>' . sprintf(__('There are no posts to display. <a href="%s">Want more traffic?</a>', 'jetpack'), 'http://en.support.wordpress.com/getting-more-site-traffic/') . '</p>';
}
echo $args['after_widget'];
return;
}
switch ($display) {
case 'list':
case 'grid':
wp_enqueue_style('widget-grid-and-list');
foreach ($posts as &$post) {
$image = Jetpack_PostImages::get_image($post['post_id']);
$post['image'] = $image['src'];
if ('blavatar' != $image['from'] && 'gravatar' != $image['from']) {
$size = (int) $get_image_options['avatar_size'];
$post['image'] = jetpack_photon_url($post['image'], array('resize' => "{$size},{$size}"));
}
}
unset($post);
if ('grid' == $display) {
echo "<div class='widgets-grid-layout no-grav'>\n";
foreach ($posts as $post) {
?>
<div class="widget-grid-view-image">
<a href="<?php
echo esc_url($post['permalink']);
?>
" title="<?php
echo esc_attr(wp_kses($post['title'], array()));
?>
" class="bump-view" data-bump-view="tp"><img src="<?php
echo esc_url($post['image']);
?>
" /></a>
</div>
<?php
}
echo "</div>\n";
} else {
echo "<ul class='widgets-list-layout no-grav'>\n";
foreach ($posts as $post) {
?>
<li>
<img src="<?php
echo esc_url($post['image']);
?>
" class='widgets-list-layout-blavatar' />
<div class="widgets-list-layout-links"><a href="<?php
echo esc_url($post['permalink']);
?>
" class="bump-view" data-bump-view="tp"><?php
echo esc_html(wp_kses($post['title'], array()));
?>
</a></div>
</li>
<?php
}
echo "</ul>\n";
}
break;
default:
echo '<ul>';
//.........这里部分代码省略.........
示例6: jetpack_print_news_sitemap
//.........这里部分代码省略.........
$post_types_in[] = $wpdb->prepare('%s', $post_type);
}
$post_types_in_string = implode(', ', $post_types_in);
/**
* Filter limit of entries to include in news sitemap.
*
* @module sitemaps
*
* @since 3.9.0
*
* @param int $count Number of entries to include in news sitemap.
*/
$limit = apply_filters('jetpack_sitemap_news_sitemap_count', 1000);
$cur_datetime = current_time('mysql', true);
$query = $wpdb->prepare("\n\t\tSELECT p.ID, p.post_title, p.post_type, p.post_date, p.post_name, p.post_date_gmt, GROUP_CONCAT(t.name SEPARATOR ', ') AS keywords\n\t\tFROM\n\t\t\t{$wpdb->posts} AS p LEFT JOIN {$wpdb->term_relationships} AS r ON p.ID = r.object_id\n\t\t\tLEFT JOIN {$wpdb->term_taxonomy} AS tt ON r.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'post_tag'\n\t\t\tLEFT JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id\n\t\tWHERE\n\t\t\tpost_status='publish' AND post_type IN ( {$post_types_in_string} ) AND post_date_gmt > (%s - INTERVAL 2 DAY)\n\t\tGROUP BY p.ID\n\t\tORDER BY p.post_date_gmt DESC LIMIT %d", $cur_datetime, $limit);
// URL to XSLT
$xsl = get_option('permalink_structure') ? home_url('news-sitemap.xsl') : home_url('/?jetpack-news-sitemap-xsl=true');
// Unless it's zh-cn for Simplified Chinese or zh-tw for Traditional Chinese,
// trim national variety so an ISO 639 language code as required by Google.
$language_code = strtolower(get_locale());
if (in_array($language_code, array('zh_tw', 'zh_cn'))) {
$language_code = str_replace('_', '-', $language_code);
} else {
$language_code = preg_replace('/(_.*)$/i', '', $language_code);
}
header('Content-Type: application/xml');
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<?xml-stylesheet type="text/xsl" href="' . esc_url($xsl) . '"?>' . "\n";
echo '<!-- generator="jetpack-' . JETPACK__VERSION . '" -->' . "\n";
?>
<!-- generator="jetpack" -->
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
>
<?php
$posts = $wpdb->get_results($query);
foreach ($posts as $post) {
setup_postdata($post);
/**
* Filter condition to allow skipping specific posts in news sitemap.
*
* @module sitemaps
*
* @since 3.9.0
*
* @param bool $skip Current boolean. False by default, so no post is skipped.
* @param WP_POST $post Current post object.
*/
if (apply_filters('jetpack_sitemap_news_skip_post', false, $post)) {
continue;
}
$GLOBALS['post'] = $post;
$url = array();
$url['loc'] = get_permalink($post->ID);
$news = array();
$news['news:publication']['news:name'] = get_bloginfo_rss('name');
$news['news:publication']['news:language'] = $language_code;
$news['news:publication_date'] = jetpack_w3cdate_from_mysql($post->post_date_gmt);
$news['news:title'] = get_the_title_rss();
if ($post->keywords) {
$news['news:keywords'] = html_entity_decode(ent2ncr($post->keywords), ENT_HTML5);
}
$url['news:news'] = $news;
// Add image to sitemap
$post_thumbnail = Jetpack_PostImages::get_image($post->ID);
if (isset($post_thumbnail['src'])) {
$url['image:image'] = array('image:loc' => esc_url($post_thumbnail['src']));
}
/**
* Filter associative array with data to build <url> node and its descendants for current post in news sitemap.
*
* @module sitemaps
*
* @since 3.9.0
*
* @param array $url Data to build parent and children nodes for current post.
* @param int $post_id Current post ID.
*/
$url = apply_filters('jetpack_sitemap_news_sitemap_item', $url, $post);
if (empty($url)) {
continue;
}
jetpack_print_sitemap_item($url);
}
wp_reset_postdata();
?>
</urlset>
<?php
$xml = ob_get_contents();
ob_end_clean();
if (!empty($xml)) {
set_transient('jetpack_news_sitemap', $xml, DAY_IN_SECONDS);
echo $xml;
}
die;
}
示例7: _generate_related_post_image_params
/**
* Generates the thumbnail image to be used for the post. Uses the
* image as returned by Jetpack_PostImages::get_image()
*
* @param int $post_id
* @uses self::get_options, apply_filters, Jetpack_PostImages::get_image, Jetpack_PostImages::fit_image_url
* @return string
*/
protected function _generate_related_post_image_params($post_id)
{
$options = $this->get_options();
$image_params = array('src' => '', 'width' => 0, 'height' => 0);
if (!$options['show_thumbnails']) {
return $image_params;
}
$thumbnail_size = apply_filters('jetpack_relatedposts_filter_thumbnail_size', array('width' => 350, 'height' => 200));
if (!is_array($thumbnail_size)) {
$thumbnail_size = array('width' => (int) $thumbnail_size, 'height' => (int) $thumbnail_size);
}
// Try to get post image
if (class_exists('Jetpack_PostImages')) {
$img_url = '';
$post_image = Jetpack_PostImages::get_image($post_id, $thumbnail_size);
if (is_array($post_image)) {
$img_url = $post_image['src'];
} elseif (class_exists('Jetpack_Media_Summary')) {
$media = Jetpack_Media_Summary::get($post_id);
if (is_array($media) && !empty($media['image'])) {
$img_url = $media['image'];
}
}
if (!empty($img_url)) {
$image_params['width'] = $thumbnail_size['width'];
$image_params['height'] = $thumbnail_size['height'];
$image_params['src'] = Jetpack_PostImages::fit_image_url($img_url, $thumbnail_size['width'], $thumbnail_size['height']);
}
}
return $image_params;
}
示例8: get_post_image
public function get_post_image($content)
{
$image = '';
if (class_exists('Jetpack_PostImages')) {
// Use the full stack of methods to find an image, except for HTML, which can cause loops
$img = Jetpack_PostImages::get_image($content->ID);
if (!empty($img['src'])) {
return $img['src'];
}
}
// If we have to fall back to the following, we only do a few basic image checks
$content = $content->post_content;
if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
$thumb_id = get_post_thumbnail_id();
$thumb = wp_get_attachment_image_src($thumb_id, 'full');
// This shouldn't be necessary, since has_post_thumbnail() is true,
// but... see http://wordpress.org/support/topic/jetpack-youtube-embeds
if (!$thumb) {
return '';
}
$image = remove_query_arg(array('w', 'h'), $thumb[0]);
} else {
if (preg_match_all('/<img (.+?)>/', $content, $matches)) {
foreach ($matches[1] as $attrs) {
$media = $img = array();
foreach (wp_kses_hair($attrs, array('http', 'https')) as $attr) {
$img[$attr['name']] = $attr['value'];
}
if (!isset($img['src']) || 0 !== strpos($img['src'], 'http')) {
continue;
} else {
$image = htmlspecialchars_decode($img['src']);
break;
}
}
}
}
return $image;
}
示例9: get_image_url
/**
* Retrieve the image URL for a post.
*
* @since 3.1.0
*
* @see Cedaro_Theme_PostMedia::get_image()
* @todo Refactor to remove dependence on Cedaro_Theme_PostMedia::get_image()
*
* @param int|WP_Post $post Optional. Post ID or object. Defaults to the current post.
* @param string|array $size Optional. The size of the image to return. Defaults to large.
* @return string Image URL.
*/
public function get_image_url($post = 0, $size = 'large')
{
$post = get_post($post);
$url = $this->get_image_url_from_cache($post, $size);
if (null !== $url) {
return apply_filters($this->theme->prefix . '_post_image_url', $url, $post);
}
// Check for a featured image first.
if (has_post_thumbnail($post->ID)) {
$data = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size);
$url = $data[0];
} elseif (class_exists('Jetpack_PostImages') && ($data = Jetpack_PostImages::get_image($post->ID))) {
$url = $data['src'];
} elseif (!class_exists('Jetpack_PostImages')) {
// Check the post content for an image.
$html = $this->get_image_in_content($post->post_content);
if (!empty($html) && preg_match('/src=[\'"]([^\'"]+)/', $html, $matches)) {
$url = $matches[1];
} else {
// Check the post's attachments.
$images = get_posts(array('post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'posts_per_page' => 1, 'fields' => 'ids', 'orderby' => 'menu_order', 'order' => 'asc'));
if (count($images)) {
$data = wp_get_attachment_image_src($images[0], $size);
$url = $data[0];
}
}
}
$this->cache_image_url($post, $size, $url);
return apply_filters($this->theme->prefix . '_post_image_url', $url, $post);
}
示例10: boardwalk_get_image
/**
* Get one image from a specified post in the following order:
* Featured Image, first attached image, first image from the_content HTML
*
* @param int $id, The post ID to check
* @param string $size The image size to return, defaults to 'featured-home-big'.
* @param string|array $attr Optional. Query string or array of attributes.
* @return string $thumb Thumbnail image with markup.
*/
function boardwalk_get_image($post_id = null, $size = 'post-thumbnail', $attr = '')
{
$post_id = null === $post_id ? get_the_ID() : $post_id;
if ('' != get_the_post_thumbnail($post_id)) {
return get_the_post_thumbnail($post_id, $size, $attr);
}
$attached_images = get_attached_media('image');
if (!empty($attached_images)) {
$first_attached_image = array_shift($attached_images);
return wp_get_attachment_image($first_attached_image->ID, $size, false, $attr);
}
if (class_exists('Jetpack_PostImages')) {
global $_wp_additional_image_sizes;
$args = array('from_thumbnail' => false, 'from_slideshow' => true, 'from_gallery' => true, 'from_attachment' => false);
$image = Jetpack_PostImages::get_image($post_id, $args);
if (!empty($image)) {
$image['width'] = '';
$image['height'] = '';
if (array_key_exists($size, $_wp_additional_image_sizes)) {
$image['width'] = $_wp_additional_image_sizes[$size]['width'];
$image['height'] = $_wp_additional_image_sizes[$size]['height'];
}
$image_src = Jetpack_PostImages::fit_image_url($image['src'], $image['width'], $image['height']);
return '<img src="' . esc_url($image_src) . '" title="' . esc_attr(strip_tags(get_the_title())) . '" class="attachment-' . esc_attr($size) . ' wp-post-image" />';
}
}
return false;
}