Last active
June 3, 2016 22:23
-
-
Save maor/3c65c8741cc41638281c to your computer and use it in GitHub Desktop.
A theme helper function for Photon (http://developer.wordpress.com/docs/photon/)
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 ch_photonize( $url = '', $params = array() ) { | |
$server_pool = rand( 0,3 ); | |
return add_query_arg( | |
$params, | |
"https://i{$server_pool}.wp.com/" . str_replace( array( 'http://', 'https://' ), '', $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 | |
// Sample usage: (in a theme, within the loop) | |
// BTW: I know there are better ways to go about it, but this is just for demonstration purposes. | |
while ( have_posts() ) : the_post(); ?> | |
<div class="post-featured-image"> | |
<?php if (has_post_thumbnail( $post->ID ) ): ?> | |
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> | |
<img src="<?php echo ch_photonize( current($image), array( 'crop' => '300,300' ) ); ?>" alt=""> | |
<?php endif; ?> | |
</div> | |
<?php endwhile; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment