function wpjam_get_post_thumbnail_uri($post = null) { $post = get_post($post); if (!$post) { return false; } $post_id = $post->ID; $post_thumbnail_uri = wp_cache_get($post_id, 'post_thumbnail_uri'); if ($post_thumbnail_uri === false) { if (has_post_thumbnail($post_id)) { $post_thumbnail_uri = wp_get_attachment_url(get_post_meta($post_id, '_thumbnail_id', true)); } elseif ($post_thumbnail_uri = apply_filters('wpjam_pre_post_thumbnail_uri', false, $post)) { // do nothing } elseif ($first_img = get_post_first_image(do_shortcode($post->post_content))) { $pre = apply_filters('pre_qiniu_remote', false, $first_img); $img_type = strtolower(pathinfo($first_img, PATHINFO_EXTENSION)); if ($pre == false && wpjam_qiniutek_get_setting('remote') && get_option('permalink_structure') && strpos($first_img, LOCAL_HOST) === false && strpos($first_img, CDN_HOST) === false) { $img_type = $img_type == 'png' ? $img_type : 'jpg'; $first_img = CDN_HOST . '/qiniu/' . $post_id . '/image/' . md5($first_img) . '.' . $img_type; } $post_thumbnail_uri = $first_img; } elseif ($post_thumbnail_uri = apply_filters('wpjam_post_thumbnail_uri', false, $post)) { //do nothing } else { $post_thumbnail_uri = wpjam_get_default_thumbnail_uri(); } wp_cache_set($post_id, $post_thumbnail_uri, 'post_thumbnail_uri', 6000); } return $post_thumbnail_uri; }
function query($q, $s = "") { global $wp_query; global $wm_post_nums; $articles = array(); $query_base = array('ignore_sticky_posts' => true, 'posts_per_page' => $wm_post_nums, 'post_status' => 'publish'); if (empty($s)) { switch ($q) { case "h": $query_more = array("order" => "DESC", "orderby" => "comment_count"); break; case "n": $query_more = array("order" => "DESC", "orderby" => "date"); break; case "r": $query_more = array("orderby" => "rand"); break; default: $query_more = array(); break; } } else { $query_more = array('s' => $s); } $weixin_query_array = array_merge($query_base, $query_more); $weixin_query_array = apply_filters('weixin_query', $weixin_query_array); $wp_query->query($weixin_query_array); if (have_posts()) { while (have_posts()) { the_post(); global $post; $title = get_the_title(); $excerpt = get_post_excerpt($post); $thumbnail_id = get_post_thumbnail_id($post->ID); if ($thumbnail_id) { $thumb = wp_get_attachment_image_src($thumbnail_id, 'thumbnail'); $thumb = $thumb[0]; } else { $thumb = get_post_first_image($post->post_content); } global $wm_thumb; if (empty($thumb) && !empty($wm_thumb)) { $thumb = $wm_thumb; } $link = get_permalink(); $articles[] = array($title, $excerpt, $link, $thumb); } } return $articles; }
function get_post_weixin_thumb($post, $size) { $post = get_post($post); $thumb = apply_filters('weixin_pre_thumb', false, $size, $post); if ($thumb === false) { $thumbnail_id = get_post_thumbnail_id($post->ID); if ($thumbnail_id) { $thumb = wp_get_attachment_image_src($thumbnail_id, $size); $thumb = $thumb[0]; } else { $thumb = get_post_first_image($post->post_content); } if (empty($thumb)) { $thumb = weixin_robot_get_setting('weixin_default'); } } $thumb = apply_filters('weixin_thumb', $thumb, $size); return $thumb; }
function tt_prev_next_post() { global $formatimg, $format; //Get Previous $next_post = get_next_post(); if (!empty($next_post)) { query_posts('p=' . $next_post->ID); if (have_posts()) { the_post(); $format = get_post_format(); $formatimg = $format == '' ? 'standart' : "format-{$format}"; $btnImg = get_post_image_for_nextprev(); if (!$btnImg) { $btnImg = get_post_first_image(); } if (!$btnImg) { $btnImg = get_youtube_vimeo_thumb_url(get_post_meta($next_post->ID, 'tt-video-embed', true)); } ?> <div id="prev" class="<?php if (!$btnImg) { echo 'no-thumb'; } ?> "> <a href="<?php the_permalink(); ?> "> <div class="lightBoxNav navLeft"></div> </a> <a href="<?php the_permalink(); ?> " class="link-content"> <div class="prev_post"><h3 class="item-title"><?php the_title(); ?> </h3><?php if ($btnImg) { echo '<img src="' . $btnImg . '" alt="">'; } ?> </div> </a> </div><?php } wp_reset_query(); } //Get Next $prev_post = get_previous_post(); if (!empty($prev_post)) { query_posts('p=' . $prev_post->ID); if (have_posts()) { the_post(); $format = get_post_format(); $formatimg = $format == '' ? 'standart' : "format-{$format}"; $btnImg = get_post_image_for_nextprev(); if (!$btnImg) { $btnImg = get_post_first_image(); } if (!$btnImg) { $btnImg = get_youtube_vimeo_thumb_url(get_post_meta($prev_post->ID, 'tt-video-embed', true)); } ?> <div id="next" class="<?php if (!$btnImg) { echo 'no-thumb'; } ?> "> <a href="<?php the_permalink(); ?> "> <div class="lightBoxNav navRight"></div> </a> <a href="<?php the_permalink(); ?> " class="link-content"> <div class="next_post"> <h3 class="item-title"><?php the_title(); ?> </h3><?php if ($btnImg) { echo '<img src="' . $btnImg . '" alt="">'; } ?> </div> </a> </div><?php } wp_reset_query(); } }