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 draw_post_header($title = '', $excerpt = '', $bg = '', $size = 'full', $parallax = 'off') { ////KC::debug(wp_get_attachment_image_src(get_post_thumbnail_id(1480), 'full')); $title = get_post_title($title); $excerpt = get_post_excerpt($excerpt); $bg = get_post_bg($bg, $size); $classes = "draw-post-header"; if ($bg == KC::$default_header_image) { $classes .= " default-bg"; $parallax = "off"; } // possibly set these from custom post types //$parallax = "off"; // on/off $title = "<h2><span>{$title}</span></h2>"; if ($excerpt) { $excerpt = "<h3><span>{$excerpt}</span></h3>"; } KC::debug($excerpt); $content = <<<EOT [et_pb_section admin_label="section" background_image="{$bg}" transparent_background="on" allow_player_pause="off" inner_shadow="off" parallax="{$parallax}" parallax_method="true" \t\tcustom_padding="" padding_mobile="on" make_fullwidth="off" use_custom_width="off" width_unit="on" make_equal="off" use_custom_gutter="off"] \t[et_pb_row admin_label="row" make_fullwidth="off" use_custom_width="off" width_unit="off" custom_width_percent="" use_custom_gutter="off" \t padding_mobile="off" allow_player_pause="off" parallax="on" parallax_method="off" make_equal="off" column_padding_mobile="on"] \t [et_pb_column type="4_4"] \t\t[et_pb_cta admin_label="Call To Action" title="" url_new_window="off" use_background_color="on" background_color="" background_layout="" text_orientation="" \t\t\tcustom_margin="" custom_padding="" custom_button="off" button_letter_spacing="0" button_use_icon="default" button_icon_placement="right" button_on_hover="on" button_letter_spacing_hover="0"] \t\t {$title} \t\t {$excerpt} \t\t[/et_pb_cta] \t [/et_pb_column] \t[/et_pb_row] [/et_pb_section] EOT; echo '<div class="' . $classes . '">' . do_shortcode($content) . '</div>'; }
/** * @param type $title - 'text', title, author * @param type $excerpt - 'text', excerpt * @param type $bg - 'url', featured, author * @param type $size - '', full * @param type $parallax - '', css, js * @param type $height - '', full */ function draw_post_header($title, $excerpt, $bg, $size, $parallax, $height) { $title = get_post_title($title); $excerpt = get_post_excerpt($excerpt); $bg = get_post_bg($bg, $size); $classes = 'draw-post-header'; if ($bg == KC::$default_header_image) { $classes .= ' default-bg'; } //$parallax = 'js'; if ($parallax === 'css') { $parallax = 'on'; $parallax_method = 'off'; } elseif ($parallax === 'js' || $parallax === 'on') { $parallax = 'on'; $parallax_method = 'on'; } else { $parallax = 'off'; $parallax_method = 'off'; } $classes .= ' parallax-' . $parallax; $classes .= ' parallax-method-' . $parallax_method; if ($title) { $title = "<h2><span>{$title}</span></h2>"; } if ($excerpt) { $excerpt = "<h3><span>{$excerpt}</span></h3>"; } // if (true || $height === 'full') { $classes .= " height-full"; $header_fullscreen = $height === 'full' ? 'on' : 'off'; $text_orientation = 'center'; // left center right $content_orientation = 'center'; // top center bottom $content = <<<EOT [et_pb_section admin_label="section" background_image="{$bg}" transparent_background="on" inner_shadow="on" parallax="{$parallax}" parallax_method="{$parallax_method}" module_id="" fullwidth="on" specialty="off"] [et_pb_fullwidth_header admin_label="Fullwidth Header" background_layout="dark" text_orientation="{$text_orientation}" header_fullscreen="{$header_fullscreen}" header_scroll_down="off" scroll_down_icon="%%0%%" parallax="" parallax_method="" content_orientation="{$content_orientation}" image_orientation="center" custom_button_one="off" button_one_letter_spacing="0" button_one_use_icon="default" button_one_icon_placement="right" button_one_on_hover="on" button_one_letter_spacing_hover="0" custom_button_two="off" button_two_letter_spacing="0" button_two_use_icon="default" button_two_icon_placement="right" button_two_on_hover="on" button_two_letter_spacing_hover="0" button_one_text="" button_one_text_size="20" button_one_border_width="2" button_one_border_radius="50" button_one_border_radius_hover="3" button_two_text_size="20" button_two_border_width="2" button_two_border_radius="50" button_two_border_radius_hover="3" background_url="" background_overlay_color="rgba(0,0,0,0)" logo_image_url="" logo_alt_text="" logo_title="" title="" button_one_url=""] {$title} {$excerpt} [/et_pb_fullwidth_header] [/et_pb_section] EOT; // } // else { // $classes .= " height-default"; // $content = <<<EOT // [et_pb_section admin_label="section" background_image="$bg" transparent_background="on" allow_player_pause="off" inner_shadow="off" // parallax="$parallax" parallax_method="$parallax_method" // custom_padding="" padding_mobile="on" make_fullwidth="off" use_custom_width="off" width_unit="on" make_equal="off" use_custom_gutter="off"] // // [et_pb_row admin_label="row" make_fullwidth="off" use_custom_width="off" width_unit="off" custom_width_percent="" use_custom_gutter="off" // padding_mobile="off" allow_player_pause="off" parallax="on" parallax_method="off" make_equal="off" column_padding_mobile="on"] // // [et_pb_column type="4_4"] // // [et_pb_cta admin_label="Call To Action" title="" url_new_window="off" use_background_color="on" background_color="" background_layout="" text_orientation="" // custom_margin="" custom_padding="" custom_button="off" button_letter_spacing="0" button_use_icon="default" button_icon_placement="right" button_on_hover="on" button_letter_spacing_hover="0"] // $title // $excerpt // [/et_pb_cta] // [/et_pb_column] // [/et_pb_row] // [/et_pb_section] //EOT; // } echo '<div class="' . $classes . '">' . do_shortcode($content) . '</div>'; }
bloginfo('charset'); ?> "> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/png" sizes="96x96" href="<?php echo get_stylesheet_directory_uri(); ?> /favicon.png"> <link rel="profile" href="http://gmpg.org/xfn/11"> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?> "> <!--meta name="description" content="<?php echo get_post_excerpt(null, 100); ?> " /--> <?php wp_head(); ?> <!-- Facebook Pixel Code --> <script> !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n; n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window, document,'script','https://connect.facebook.net/en_US/fbevents.js');
<img src="<?php echo $image; ?> " alt="<?php echo get_the_title(); ?> "> </div> <div class="card-header"> <?php echo get_the_title(); ?> </div> <div class="card-copy"> <p> <?php echo get_post_excerpt(); ?> <?php $categories = get_the_category(); if ($categories) { //echo $categories[0]->name . ' '; } ?> </p> </div> </a> </div>
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $before_widget = '<section class="box featured">'; $before_title = '<h3>'; $after_title = '</h3>'; $after_widget = '</section>'; $title = apply_filters('widget_title', empty($instance['title']) ? __('Featured project') : $instance['title'], $instance, $this->id_base); if (empty($instance['length']) || !($length = absint($instance['length']))) { $length = 20; } $posts = new WP_Query(array('cat' => $instance['category'], 'orderby' => 'date')); if ($posts->have_posts()) { ?> <?php echo $before_widget; ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <!-- first-posts --> <?php while ($posts->have_posts()) { $posts->the_post(); ?> <figure class="photo"> <?php post_thumbnail(220, 160); ?> </figure> <h4><?php echo get_title_excerpt(0); ?> </h4> <p><?php echo get_post_excerpt($length, ''); break; ?> </p> <?php } ?> <?php echo $after_widget; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } }
?> <img src="<?php echo get_template_directory_uri(); ?> /images/portfolio-290x181.jpg" width="274" height="165" alt="no thumbnail" > <?php } ?> </figure> <h3> <?php echo get_title_excerpt(); ?> </h3> <p><?php echo get_post_excerpt(20); ?> </p> <nav class="nav-blog"> <ul> <li><a href="<?php echo get_permalink(); ?> ">Read more</a></li> <li><?php shredfast_comments_popup_link('<span class="leave-reply">' . __('Reply', 'twentyeleven') . '</span>', _x('1', 'comments number', 'twentyeleven'), _x('%', 'comments number', 'twentyeleven')); ?> </li> </ul> </nav> </article>
public function query($keyword = '') { $weixin_count = weixin_robot_get_setting('weixin_count'); // 获取除 page 和 attachmet 之外的所有日志类型 $post_types = get_post_types(array('exclude_from_search' => false)); unset($post_types['page']); unset($post_types['attachment']); $weixin_query_array = array('s' => $keyword, 'ignore_sticky_posts' => true, 'posts_per_page' => $weixin_count, 'post_status' => 'publish', 'post_type' => $post_types); $weixin_query_array = apply_filters('weixin_query', $weixin_query_array); if (empty($this->response)) { if (isset($weixin_query_array['s'])) { $this->response = 'query'; } elseif (isset($weixin_query_array['cat'])) { $this->response = 'cat'; } elseif (isset($weixin_query_array['tag_id'])) { $this->response = 'tag'; } } global $wp_the_query; $wp_the_query->query($weixin_query_array); $items = ''; $counter = 0; if ($wp_the_query->have_posts()) { while ($wp_the_query->have_posts()) { $wp_the_query->the_post(); $title = apply_filters('weixin_title', get_the_title()); $excerpt = apply_filters('weixin_description', get_post_excerpt('', apply_filters('weixin_description_length', 150))); $url = apply_filters('weixin_url', get_permalink()); if ($counter == 0) { $thumb = get_post_weixin_thumb('', array(640, 320)); } else { $thumb = get_post_weixin_thumb('', array(80, 80)); } $items = $items . $this->get_item($title, $excerpt, $thumb, $url); $counter++; } } $articleCount = count($wp_the_query->posts); if ($articleCount > $weixin_count) { $articleCount = $weixin_count; } if ($articleCount) { echo sprintf($this->get_picTpl(), $articleCount, $items); } else { weixin_robot_not_found_reply($keyword); } }
/** * Generate posts array * * @param $posts * @param $offset * @param $taxonomy * @param $eager_loading * @param $post_type * @param $final_posts * * @return mixed */ function get_final_posts($posts, $offset, $taxonomy, $eager_loading, $final_posts) { foreach ($posts as $post) { $final_post = array(); $post_id = $post->ID; $key = http_build_query(array('post_id' => "{$post_id}", "type" => "ml_post")); $cache = get_cache('ml_post', $key); if (!empty($cache)) { $final_posts["posts"][] = unserialize($cache); continue; } $final_post["post_id"] = "{$post_id}"; $final_post["post_type"] = $post->post_type; $final_post["author"] = array(); $final_post["categories"] = array(); $final_post["author"]["name"] = html_entity_decode(get_author_name($post->post_author)); $final_post["author"]["author_id"] = $post->post_author; $final_post["title"] = strip_tags($post->post_title); $final_post["title"] = html_entity_decode($final_post["title"], ENT_QUOTES); $final_post["videos"] = array(); $final_post["images"] = array(); if ($offset > 0 && is_sticky($post_id)) { continue; } /** comments ======================================================================== **/ $images = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image')); $comments_count = wp_count_comments($post_id); $final_post["comments-count"] = 0; if ($comments_count) { $final_post["comments-count"] = intval($comments_count->approved); } /** permalink ======================================================================== **/ $final_post["permalink"] = get_permalink($post_id); if (strlen(trim(get_option('ml_custom_field_url', ''))) > 0) { $custom_url_value = get_post_meta($post->ID, get_option('ml_custom_field_url'), true); if (strlen(trim($custom_url_value)) > 0) { $final_post["permalink"] = $custom_url_value; } } /** categories ======================================================================== **/ $categories = get_the_category($post_id); foreach ($categories as $category) { $final_post["categories"][] = array("cat_id" => "{$category->cat_ID}", "name" => $category->cat_name, "slug" => $category->category_nicename); } if ($taxonomy !== 'category' && !empty($taxonomy)) { $terms = wp_get_post_terms($post_id, $taxonomy); foreach ($terms as $term) { $final_post["categories"][] = array("cat_id" => "{$term->term_id}", "name" => $term->name, "slug" => $term->slug); } } /** date ======================================================================== **/ $final_post["date"] = $post->post_date; if (get_option('ml_datetype', 'prettydate') == 'datetime') { $final_post["date_display"] = date_i18n(get_option('ml_dateformat', 'F j, Y'), strtotime($post->post_date), get_option('gmt_offset')); } /** media ======================================================================== **/ try { $video_id = get_the_first_youtube_id($post); } catch (Exception $e) { } try { //featured image $main_image_url = get_the_first_image($post); } catch (Exception $e) { //error getting or resizing the images } if ($video_id != null) { $final_post["videos"][] = $video_id; } if ($main_image_url != null) { $image = array("full" => $main_image_url, "thumb" => array("url" => $main_image_url), "big-thumb" => array("url" => $main_image_url)); $final_post["images"][0] = $image; } if (strlen(get_option('ml_custom_featured_image')) > 0 && class_exists('MultiPostThumbnails')) { $customImageUrl = MultiPostThumbnails::get_post_thumbnail_url(get_post_type($post->ID), Mobiloud::get_option('ml_custom_featured_image'), $post->ID, 'large'); if ($customImageUrl !== false) { $final_post["images"][0] = array("full" => $customImageUrl, "thumb" => array("url" => $customImageUrl), "big-thumb" => array("url" => $customImageUrl)); } } foreach ((array) $images as $image) { $imageToAdd = array(); $imageToAdd["full"] = wp_get_attachment_image_src($image->ID, 'full'); $imageToAdd["thumb"] = wp_get_attachment_image_src($image->ID, 'thumbnail'); $imageToAdd["imageId"] = $image->ID; $final_post["images"][] = $imageToAdd; } /** Content ======================================================================== **/ //capturing the html output generated ob_start(); include "post/post.php"; $html_content = ob_get_clean(); //replace relative URLs with absolute $html_content = preg_replace("#(<\\s*a\\s+[^>]*href\\s*=\\s*[\"'])(?!http|/)([^\"'>]+)([\"'>]+)#", '$1' . $final_post["permalink"] . '/$2$3', $html_content); $final_post["content"] = $html_content; /** Sticky ======================================================================== **/ //sticky ? $final_post["sticky"] = is_sticky($post->ID) || $post->sticky; /** Custom field ======================================================================== **/ if (strlen(get_option('ml_custom_field_name', '')) > 0) { if (get_option('ml_custom_field_name', '') == "excerpt") { $custom_field_val = html_entity_decode(urldecode(strip_tags(get_post_excerpt($post->ID)))); $final_post['custom1'] = $custom_field_val; } else { $custom_field_val = get_post_meta($post->ID, get_option('ml_custom_field_name', ''), true); $final_post['custom1'] = $custom_field_val; } } //excerpt $final_post['excerpt'] = html_entity_decode(urldecode(strip_tags(get_post_excerpt($post->ID)))); $final_post['excerpt'] = str_replace('Read More', '', $final_post['excerpt']); if (get_post_format($post) == 'status') { $final_post["title"] = $post->post_content; $final_post["content"] = ""; $final_post['custom1'] = ""; $final_post['excerpt'] = ""; } set_cache('ml_post', $key, serialize($final_post)); $final_posts["posts"][] = $final_post; } return $final_posts; }
function weixin_rebot_sent_user($weixin_openid, $content, $reply_type = 'text') { $weixin_robot_access_token = weixin_robot_get_access_token(); $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $weixin_robot_access_token; $request = array(); $request['touser'] = $weixin_openid; if ($reply_type == 'text') { $request['msgtype'] = 'text'; $request['text'] = array('content' => urlencode($content)); } elseif ($reply_type == 'img') { $articles = $article = array(); $img_reply_query = new WP_Query(array('post__in' => explode(',', $content), 'orderby' => 'post__in', 'post_type' => 'any')); if ($img_reply_query->have_posts()) { while ($img_reply_query->have_posts()) { $img_reply_query->the_post(); $article['title'] = urlencode(apply_filters('weixin_title', get_the_title())); $article['description'] = urlencode(apply_filters('weixin_description', get_post_excerpt('', apply_filters('weixin_description_length', 150)))); $article['url'] = urlencode(add_query_arg('weixin_openid', $weixin_openid, apply_filters('weixin_url', get_permalink()))); if ($counter == 0) { $article['picurl'] = get_post_weixin_thumb('', array(640, 320)); } else { $article['picurl'] = get_post_weixin_thumb('', array(80, 80)); } $articles[] = $article; } $request['msgtype'] = 'news'; $request['news'] = array('articles' => $articles); } wp_reset_query(); } elseif ($reply_type == 'image') { $request['msgtype'] = 'image'; $request['image'] = array('media_id' => urlencode($content)); } elseif ($reply_type == 'voice') { $request['msgtype'] = 'voice'; $request['voice'] = array('media_id' => urlencode($content)); } elseif ($reply_type == 'video') { //$request['msgtype'] = 'video'; //$request['video'] = array('media_id'=>urlencode($content),'title'=>'','description'=>''); } elseif ($reply_type == 'music') { //$request['msgtype'] = 'music'; //$request['music'] = array('media_id'=>urlencode($content)); } if (isset($request['msgtype']) && $request['msgtype']) { $response = wp_remote_post($url, array('body' => urldecode(json_encode($request)), 'sslverify' => false)); if (is_wp_error($response)) { echo $response->get_error_code() . ':' . $response->get_error_message(); exit; } $response = json_decode($response['body'], true); if ($response['errcode']) { return $response['errcode'] . ': ' . $response['errmsg']; } else { return '发送成功'; } } }
<?php if (has_post_thumbnail($post_id)) { ?> <?php post_thumbnail(615, 284); ?> <?php } ?> </figure> <p> <?php echo get_post_excerpt(55, ''); ?> </p> <a href="<?php echo get_permalink(); ?> ">Read more ...</a> <?php } ?> </article><!-- #post-<?php the_ID(); ?> -->
function weixin_robot_enqueue_scripts() { global $post; $img = apply_filters('weixin_share_img', get_post_weixin_thumb($post, array(120, 120))); $link = apply_filters('weixin_share_url', get_permalink()); $title = apply_filters('weixin_share_title', get_the_title()); $desc = apply_filters('weixin_share_desc', get_post_excerpt($post)); $weixin_openid = weixin_robot_get_user_openid(); wp_enqueue_script('jquery'); wp_enqueue_script('weixin', WEIXIN_ROBOT_PLUGIN_URL . '/static/weixin-share.js', array('jquery')); wp_localize_script('weixin', 'weixin_data', array('appid' => '', 'fakeid' => '', 'img' => $img, 'link' => $link, 'title' => $title, 'desc' => $desc, 'credit' => $is_IIS ? 0 : weixin_robot_get_setting('weixin_credit'), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('weixin_share'), 'post_id' => get_the_ID(), 'weixin_openid' => $weixin_openid, 'notify' => weixin_robot_get_setting('weixin_share_notify'))); }