Created
February 12, 2017 05:05
-
-
Save mwordpress/d79a75f8ba0d49c74894a6b71d98b8ff to your computer and use it in GitHub Desktop.
the codes listed here is part of the following article : https://www.mwordpress.net/how-to-insert-thumbnail-to-woordpress-with-timthumb/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase /media/ | |
RewriteRule ^resizer/(.*)x(.*)/r/(.*) resizer/resize.php?src=http://sitename.com/wp-content/uploads/$3&h=$2&w=$1&zc=0&s=1 | |
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function show_thumb($width, $height, $class, $postid, $quality) { | |
if ( has_post_thumbnail() ) { | |
$img = wp_get_attachment_image_src( get_post_thumbnail_id($postid), 'full' ); | |
$url = $img['0']; | |
echo '<img class="'.$class.'" src="'.home_url().'/media/resizer/'.$width.'x'.$height.'/r/'.remove_path($url).'" alt="'. get_the_title($postid).'" height="'.$height.'" width="'.$width.'" />'; | |
} | |
} | |
function remove_path($url = ”) { | |
if ($url == 'http://' OR $url == 'https://'){ | |
return $url; | |
} | |
$url = parse_url($url); | |
$url = explode('/', $url['path']); | |
$url = array_slice($url, -3, 3, false); | |
$url = $url['0'].'/'.$url['1'].'/'.$url['2']; | |
return $url; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function show_thumb($width, $height, $class, $postid, $quality) { | |
if ( has_post_thumbnail() ) { | |
$img = wp_get_attachment_image_src( get_post_thumbnail_id($postid), 'full' ); | |
$url = $img['0']; | |
echo '<img class="'.$class.'" src="'.get_bloginfo('template_directory').'/resize.php?src='.$url.'&w='.$width.'&h='.$height.'&zc=0&s=1&q='.$quality.'" alt="'. get_the_title($postid).'" height="'.$height.'" width="'.$width.'" />'; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Loop | |
while ( have_posts() ) : the_post(); | |
?> | |
<div class="hentry"> | |
<h2 class="entry-title"> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
</h2> | |
<div class="thumbnail"> | |
<?php show_thumb(300, 150, ‘img-responsive’, $post->ID, 100); ?> | |
</div> | |
<p><?php the_content(”); ?></p> | |
</div> | |
<?php | |
endwhile; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment