Wordpress帖子缩略图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress帖子缩略图相关的知识,希望对你有一定的参考价值。
Universal WordPress function for thumbnails
/** * Post thumbnail * * @global mixed $post Post object * @param int $width Thumbnail width * @param int $height Thumbnail height * @param int $p Post/page ID * @param bool $echo Echo/return */ function gn_post_thumbnail( $width = 150, $height = 150, $p = false, $echo = true ) { // Config $default = get_template_directory_uri() . '/images/thumbnail.png'; // default image $meta = 'thumbnail'; // meta field name global $post; $id = ( $p ) ? $p : $post->ID; $alt = get_the_title( $id ); // Get post attachments 'post_type' => 'attachment', 'numberposts' => 1, 'order' => 'ASC', 'post_status' => null, 'post_parent' => $id ) ); // Post thumbnail if ( has_post_thumbnail( $id ) ) { $image = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'full' ); $src = $image[0]; } // Meta field elseif ( get_post_meta( $id, $meta, true ) ) { $src = get_post_meta( $id, $meta, true ); } // First post image elseif ( $attachments ) { $src = $attachments[0]['guid']; } // No matches, default image else { $src = $default; } // Markup $return = '<img src="' . $timthumb . '?src=' . $src . '&w=' . $width . '&h=' . $height . '&zc=1&q=100" width="' . $width . '" height="' . $height . '" alt="' . $alt . '" />'; // Result if ( $echo ) echo $return; else return $return; }
以上是关于Wordpress帖子缩略图的主要内容,如果未能解决你的问题,请参考以下文章