Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pietergoosen_excerpt_175_words( $length ) {
- return 175;
- }
- add_filter( 'excerpt_length', 'pietergoosen_excerpt_175_words' );
- function pietergoosen_get_first_image() {
- global $post;
- $first_img = '';
- if( $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches))
- $first_img = $matches [1] [0];
- return $first_img;
- }
- function pietergoosen_check_if_url_exist($url) {
- $headers = wp_get_http_headers($url);
- if (!is_array($headers)) :
- return FALSE;
- elseif (isset($headers["content-type"]) && (strpos($headers["content-type"],"image") !== false)) :
- return TRUE;
- else :
- return FALSE;
- endif;
- }
- function pietergoosen_adjust_image_size($image, $alt, $newwidth, $newheight) {
- if (!file_exists($image) && !pietergoosen_check_if_url_exist($image)) return '';
- list($width, $height, $type, $attr) = getimagesize($image);
- if (!$width || !$height) return '';
- if ($newwidth)
- $newheight = intval($newwidth/$width * $height);
- else
- $newwidth = intval($newheight/$height * $width);
- return '<img src="' . $image . '" width=' . $newwidth . ' height='. $newheight . ' alt=' . $alt . '/>';
- }
- <div class="alignleft-excerpt">
- <a href="<?php echo pietergoosen_get_first_image() ?>" title="<?php printf( the_title_attribute( 'echo=0' ) ); ?>" rel="lightbox">
- <?php echo pietergoosen_adjust_image_size(pietergoosen_get_first_image(), get_the_title(), 250, 0); ?>
- </a>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment