?> "><?php // 判断该文章是否设置的缩略图,如果有则直接显示 if (has_post_thumbnail()) { the_post_thumbnail('medium', array('alt' => trim(strip_tags($post->post_title)), 'title' => trim(strip_tags($post->post_title)))); } else { //如果文章没有设置缩略图,则查找文章内是否包含图片 $content = $post->post_content; preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER); $n = count($strResult[1]); if ($n > 0) { // 如果文章内包含有图片,就用第一张图片做为缩略图 echo '<a href="' . get_permalink() . '"><img src="' . $strResult[1][0] . '" width = "140" height="100"/></a>'; } else { // 如果文章内没有图片,则用判断是否为视频。 $imgurl = videclass::parseimgurl($content); if ($imgurl) { echo "<a href=" . get_permalink() . "><img src=" . $imgurl . " width = '140' height='100' /></a>"; } else { //如果不是视频内容则自动匹配默认缩略图 $random = mt_rand(1, 20); echo '<a href="' . get_permalink() . '"><img src="' . get_bloginfo('stylesheet_directory') . '/images/random/tb' . $random . '.jpg" /></a>'; } } } ?> </a></div></div> <div class="entry_post"> <span><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 240, "...", "utf-8"); ?>
function vide_the_thumbnail() { global $post; // 判断该文章是否设置的缩略图,如果有则直接显示 if (has_post_thumbnail()) { the_post_thumbnail('largevideo'); } else { //没有就显示系统的视频图片 $content = $post->post_content; $imgurl = videclass::parseimgurl($content); if ($imgurl) { echo "<img src=" . $imgurl . " width = '230' height='173' />"; } } }