function get_post_thumb($post_id, $width, $height, $custom = "image") { //universal thumb function $show_no_image = get_option("bordeaux_show_first_thumb"); $custom_image = get_post_custom_values($custom, $post_id); //get custom field value $custom_image = $custom_image[0]; if ($custom_image == "" && $custom != "image") { $custom = "bordeaux_slider_image"; $custom_image = get_post_custom_values($custom, $post_id); //get custom field value $custom_image = $custom_image[0]; } $meta = get_post_meta($post_id, "_thumbnail_id", true); //get wordpress built in thumbnail value $first_from_post = get_first_image($post_id); //get first image form post if ($custom_image != "") { //custom field value $file = $custom_image; if (strpos($file, "wp-content") !== false) { $pos = strpos($file, "/wp-content"); $file = substr($file, $pos); } $src = get_template_directory_uri(); $src .= "/timthumb.php?src="; $src .= $file; $src .= "&w={$width}&h={$height}&zc=1&q=100"; $show_image = true; } elseif ($meta) { //built in thumb $file = site_url() . "/wp-content/uploads/" . get_post_meta($meta, "_wp_attached_file", true); $src = get_template_directory_uri(); $src .= "/timthumb.php?src="; $src .= $file; $src .= "&w={$width}&h={$height}&zc=1&q=100"; $show_image = true; } elseif ($first_from_post != false && $custom != "bordeaux_slider_image") { //first attached image $file = $first_from_post; if (strpos($file, "wp-content") !== false) { $pos = strpos($file, "/wp-content"); $file = substr($file, $pos); } $src = get_template_directory_uri(); $src .= "/timthumb.php?src="; $src .= $file; $src .= "&w={$width}&h={$height}&zc=1&q=100"; $show_image = true; } else { //no image $src = get_template_directory_uri() . '/images/no-image-' . $width . 'x' . $height . '.jpg'; if ($show_no_image == "on") { $show_image = true; } else { $show_image = false; } } return array("src" => $src, "show" => $show_image); }
function hero_social_sharing_buttons($content) { // Show this on post and page only. Add filter is_home() for home page global $post, $posts; // Get current page URL $shortURL = get_permalink(); $thumb = get_first_image(); if (!$thumb) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); $thumb = $thumb[0]; } // Get current page title // $shortTitle = get_the_title(); --> update below $shortTitle = str_replace(' ', '%20', get_the_title()); // Construct sharing URL without using any script $twitterURL = 'https://twitter.com/intent/tweet?text=' . $shortTitle . '&url=' . $shortURL . '&via=' . hero_options('twitter'); $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u=' . $shortURL; $googleURL = 'https://plus.google.com/share?url=' . $shortURL; $pinterestURL = 'http://pinterest.com/pin/create/button/?url=' . $shortURL . '&media=' . $thumb . '&description=' . $shortTitle; // Add sharing button at the end of page/page content $content .= '<div class="social">'; $content .= '<a class="fb" href="' . $twitterURL . '" target="_blank"><i class="fa fa-twitter"></i></a>'; $content .= '<a class="tw" href="' . $facebookURL . '" target="_blank"><i class="fa fa-facebook"></i></a>'; $content .= '<a class="gpls" href="' . $googleURL . '" target="_blank"><i class="fa fa-google-plus"></i></a>'; $content .= '<a class="pin" href="' . $pinterestURL . '" target="_blank"><i class="fa fa-pinterest"></i></a>'; $content .= '</div>'; return $content; }
/** * Returns the featured image or the first image in the post. */ function get_main_image($post_id) { if (has_post_thumbnail($post_id)) { echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">'; the_post_thumbnail(array(275, 250)); echo '</a>'; } else { echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">'; echo '<img src="' . get_first_image() . '" alt="" />'; echo '</a>'; } }
function facebook_open_graph_init() { global $fbappID, $fbadminID, $fbimage; if (have_posts()) { while (have_posts()) { the_post(); } } $title = single_post_title('', FALSE); $url = get_permalink(); echo <<<EOD <!-- Facebook Open Graph --> <meta property="fb:app_id" content="{$fbappID}" /> <meta property="fb:admins" content="{$fbadminID}" /> EOD; if (is_single() || is_page()) { $description = strip_tags(get_the_excerpt($post->ID)); $image = get_first_image(); echo <<<EOD <meta property="og:title" content="{$title}" /> <meta property="og:description" content="{$description}" /> <meta property="og:type" content="article" /> <meta property="og:image" content="{$image}" /> <meta property="og:url" content="{$url}"/> EOD; } else { $sitename = get_bloginfo('name'); $description = get_bloginfo('description'); $url = get_bloginfo('url'); echo <<<EOD <meta property="og:site_name" content="{$sitename}" /> <meta property="og:description" content="{$description}" /> <meta property="og:type" content="website" /> <meta property="og:image" content="{$fbimage}" /> <meta property="og:url" content="{$url}"/> EOD; } }
//print '<h3 class="h3title"><span>Latest news</span><span class="fr"><a href="#" class="switch txt_r fr"> </a></span></h3>'; $class = 'first'; $post_number = 1; ?> <?php while (have_posts()) { the_post(); $img_description = ''; if (get_post_thumbnail_id($post->ID)) { $post_img = wp_get_attachment_image(get_post_thumbnail_id($post->ID), '62x62', ''); $post_img_big = wp_get_attachment_image(get_post_thumbnail_id($post->ID), 'featured_540x270', ''); $img_description = de_getPostImageDescription($post->ID, get_post_thumbnail_id($post->ID)); } else { $post_img_big = get_first_image($post->ID, '540x270'); $post_img = get_first_image($post->ID, '54x54'); } ?> <?php if ($post_number == 1) { ?> <!--Category content--> <div class="cat_content"> <?php echo $post_img_big; ?> <h2><a href="<?php the_permalink(); echo '#more'; ?>
function insert_fb_in_head() { global $post; if (!is_singular()) { //if it is not a post or a page return; } echo '<meta property="og:title" content="' . get_the_title() . '"/>'; echo '<meta property="og:type" content="article"/>'; echo '<meta property="og:url" content="' . get_permalink() . '"/>'; echo '<meta name="twitter:card" content="summary" />'; echo '<meta name="twitter:url" content="' . get_permalink() . '"/>'; echo '<meta name="twitter:title" content="' . get_the_title() . '"/>'; echo '<meta name="twitter:site" content="@e27co" />'; echo '<meta name="twitter:site:id" content="15315691" />'; echo '<meta name="twitter:description" content="' . substr(strip_tags($post->post_content), 0, 200) . '" />'; //echo '<meta property="fb:admins" content="e27"/>'; if (has_post_thumbnail($post->ID)) { //the post does not have featured image, use a default image $thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); echo '<meta property="og:image" content="' . esc_attr($thumbnail_src[0]) . '"/>'; echo '<meta name="twitter:image" content="' . esc_attr($thumbnail_src[0]) . '"/>'; echo '<link rel="image_src" href="' . esc_attr($thumbnail_src[0]) . '" />'; } elseif (get_first_image($post->ID) != null) { $thumbnail_src = get_first_image($post->ID); echo '<meta property="og:image" content="' . esc_attr($thumbnail_src) . '"/>'; echo '<meta name="twitter:image" content="' . esc_attr($thumbnail_src) . '"/>'; echo '<link rel="image_src" href="' . esc_attr($thumbnail_src) . '" />'; } else { $default_image = "http://e27.sg/wp-content/themes/greenisgood/img/e27-logo.png"; //replace this with a default image on your server or an image in your media library echo '<meta property="og:image" content="' . $default_image . '"/>'; echo '<meta name="twitter:image" content="' . $default_image . '"/>'; echo '<link rel="image_src" href="' . $default_image . '" />'; } echo "\n"; }
function get_post_thumb($post_id, $width, $height, $custom = "image", $file = false, $original = false, $retina = false) { //universal thumb function $show_no_image = get_option(THEME_NAME . "_show_no_image_thumb"); if ($post_id != false) { $custom_image = get_post_custom_values($custom, $post_id); //get custom field value $custom_image = $custom_image[0]; } else { $custom_image = false; } $upload_dir = wp_upload_dir(); if ($custom_image != false && $custom != "image" && $file == false) { $src = array(); $custom = THEME_NAME . "_homepage_image"; $custom_image = get_post_custom_values($custom, $post_id); //get custom field value $src['url'] = $custom_image[0]; } $meta = get_post_meta($post_id, "_thumbnail_id", true); //get wordpress built in thumbnail value $first_from_post = get_first_image($post_id); //get first image form post if ($custom_image && $custom == THEME_NAME . "_homepage_image" && $file == false) { //built in thumb $custom = THEME_NAME . "_homepage_image"; $custom_image = get_post_custom_values($custom, $post_id); //get custom field value $file = $custom_image[0]; $src = array(); if ($original == false) { $src['url'] = mr_image_resize($file, $width, $height, true, '', $retina); } else { $src['url'] = $file; } $show_image = true; } elseif (get_the_post_thumbnail($post_id) != '' && $meta && $file == false) { //built in thumb $file = $upload_dir["baseurl"] . "/" . get_post_meta($meta, "_wp_attached_file", true); $src = array(); if ($original == false) { $src['url'] = mr_image_resize($file, $width, $height, true, '', $retina); } else { $src['url'] = $file; } $show_image = true; } elseif ($first_from_post != false && $custom != THEME_NAME . "_homepage_image" && !get_the_post_thumbnail($post_id) && $file == false) { //first attached image $file = $first_from_post; if (strpos($file, "wp-content") !== false) { $pos = strpos($file, "/wp-content"); $file = substr($file, $pos); } $src = array(); if ($original == false) { $src['url'] = mr_image_resize(site_url() . $file, $width, $height, true, '', $retina); } else { $src['url'] = $file; } $show_image = true; } elseif ($file != false) { $src['url'] = mr_image_resize($file, $width, $height, true, '', $retina); $show_image = true; } else { //no image $src['url'] = get_template_directory_uri() . '/images/no-image-' . $width . 'x' . $height . '.jpg'; if ($show_no_image == "on") { $show_image = true; } else { $show_image = false; } } return array("src" => $src['url'], "show" => $show_image); }
<!--Latest posts--> <div class="b c_1"> <div> <h3 class="h3title"><span><?php _e('Latest news', 'cosmotheme'); ?> </span></h3> </div> </div> <div class="b c_4 latest"> <?php foreach ($latest_posts as $post) { if (get_post_thumbnail_id($post->ID)) { $latest_post_img = wp_get_attachment_image(get_post_thumbnail_id($post->ID), 'latest', ''); } else { $latest_post_img = get_first_image($post->ID, '214x159'); } ?> <div> <a href="<?php the_permalink(); echo '#more'; ?> "><?php echo $latest_post_img; ?> </a> <h4><a href="<?php the_permalink(); echo '#more'; ?>
/** * Displays the url of the post first image (the featured image by default) * @param array $params */ function the_first_image($params = array()) { $params = wp_parse_args($params); # override object param $params['object'] = FALSE; $fi = get_first_image($params); echo empty($fi) ? WPTT_DEFAULT_IMAGE : $fi; }
<a class="backward navigation" id="prev_navigation"><?php _e('previous', 'cosmotheme'); ?> </a> <div class="slides_control" id="slides_control" style="position: absolute; width: 2820px; height: 270px; left: -940px;"></div> <div class="slideshow"> <?php $img_count = 1; foreach ($featured_posts as $post) { $img_description = ''; if (get_post_thumbnail_id($post->ID)) { $post_img = wp_get_attachment_image(get_post_thumbnail_id($post->ID), 'featured_540x270', ''); $img_description = de_getPostImageDescription($post->ID, get_post_thumbnail_id($post->ID)); } else { $post_img = get_first_image($post->ID, '540x270'); } ?> <div class="cat_content " <?php if ($img_count > 1) { echo 'style="display:none"'; } ?> > <?php echo $post_img; ?> <h2><a href="<?php the_permalink();
"><?php the_title(); ?> </a></h2> <?php // get_template_part('templates/entry-meta'); ?> </header> <div class="entry-summary"> <?php if (get_the_post_thumbnail($post_id) != '') { echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">'; the_post_thumbnail(array(275, 250)); echo '</a>'; } else { echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">'; echo '<img src="' . get_first_image() . '" alt="" />'; echo '</a>'; } ?> <?php // the_excerpt(); ?> </div> </article>
item <?php if ($mzo_transition == 'horizontal_vertical' && $cnt % 2 == 0 || $mzo_transition == 'horizontal') { echo 'fl'; } ?> " id="<?php echo $cnt; ?> "> <div class="content"> <ul class="container"> <li class='grid_820' style="width: 908px; "> <img src="<?php echo get_first_image($parent); ?> " title="<?php echo $parent->post_title; ?> " alt="<?php echo $parent->post_title; ?> " /> <h2><?php echo $page->post_title; ?> </h2> <?php $content = wpautop($page->post_content); ?>
the_post(); ?> <div class="single-post" id="post-<?php the_ID(); ?> "> <div class="single-post-image"><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "><?php get_first_image(); ?> </a></div> <div class="single-post-text"> <h2><a href="<?php the_permalink(); ?> " rel="bookmark" title="Permanent Link to <?php the_title(); ?> "><?php the_title(); ?> </a></h2> <div class="single-post-content"><?php
public function getFirstImage($strHTML) { return get_first_image($strHTML); }
/** * Get page preview image (facebook) */ function the_preview_image() { global $post; if (has_post_thumbnail() && !is_front_page()) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'facebook'); echo $thumb[0]; } elseif (get_first_image() && !is_front_page()) { echo get_first_image('facebook'); } else { echo get_bloginfo('template_directory') . '/assets/img/facebook.jpg'; } }
public function post_to_facebook($blog_data) { require_once HOME_PATH . '/include/facebook/facebook.php'; $facebook = new Facebook(array('appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET, 'cookie' => true, 'scope' => 'manage_pages')); $user_id = $facebook->getUser(); print_r($user_id); $access_token = $facebook->getAccessToken(); print_r($access_token); $attachment = array('access_token' => $access_token, 'message' => 'this is my message', 'name' => 'name', 'link' => ROOT_URL . $blog_data['url'] . '.htm', 'caption' => $blog_data['title'], 'description' => $blog_data['title']); if ($image = get_first_image($blog_data['body'])) { $attachment['picture'] = $image; } $facebook->api(FACEBOOK_BLOG_PAGE . '/feed', 'post', $attachment); }