Example #1
0
function wp_thumbnails_for_homepage_preview()
{
    global $wpdb;
    $now = current_time('mysql', 1);
    $sql = "SELECT distinct post_id\n\tFROM {$wpdb->postmeta}, {$wpdb->posts}\n\tWHERE post_id = ID\n\tAND meta_key IN ('ta-thumbnail')\n\tAND meta_value NOT LIKE '%NOIMAGEINPOST%'\n\tAND post_status = 'publish' \n\tAND post_date_gmt < '{$now}' \n\tAND post_type = 'post'\n\tORDER BY post_id DESC\n\tLIMIT 1";
    $result = @mysql_query($sql, $wpdb->dbh);
    $number = @mysql_num_rows($result);
    if ($number == 1) {
        $row = mysql_fetch_array($result);
        $post_id = $row['post_id'];
        $post = get_post($post_id);
        $post_content = "wp-thumbnails-preview" . $post->post_content;
        $post_content = wp_thumbnails_excerpt($post_content);
        $post_content = str_replace("wp-thumbnails-preview", "", $post_content);
        $post_id = "id=" . $post_id;
        echo "<div style=\"width:550px;\">";
        wp_thumbnails_for_homepage($post_id);
        echo $post_content;
        echo "</div>";
    }
}
Example #2
0
function wp_thumbnails_for_homepage_auto_excerpt($excerpt)
{
    $auto = get_option('thumbnails_anywhere_options');
    if (is_home() && $auto['auto_home'] == "true" || is_category() && $auto['auto_category'] == "true" || is_search() && $auto['auto_search'] == "true" || is_tag() && $auto['auto_tag_page'] == "true") {
        $style = "single";
        if (is_home()) {
            $style = $auto['auto_home_style'];
        } else {
            if (is_category()) {
                $style = $auto['auto_cat_style'];
            } else {
                if (is_tag()) {
                    $style = $auto['auto_tag_style'];
                } else {
                    if (is_search()) {
                        $style = $auto['auto_search_style'];
                    }
                }
            }
        }
        if ($style == "multiple") {
            $thumbnail = wp_thumbnails_for_single_post('display=false');
        } else {
            if ($style == "smart") {
                $thumbnail = wp_thumbnails_for_smart_homepage('display=false');
            } else {
                $thumbnail = wp_thumbnails_for_homepage('display=false');
            }
        }
        //当前的 filter 也就是 $wp_current_filter 数组中的最后一个,end() 操作数组指针返回数组中最后一个值。
        //global $wp_current_filter;
        //echo "current filters in auto_excerpt: ".end( $wp_current_filter )."<br>";
        return $thumbnail . $excerpt;
    } else {
        return $excerpt;
    }
}