Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getPDFimg($atts) {
- extract( shortcode_atts( array(
- 'size'=>'full',
- ), $atts ) );
- $image_url = str_replace(".pdf", "-pdf.jpg", types_render_field( "document-file", array('output'=> 'raw'))); // publication_document = your field name
- $dirname = str_replace('.jpg','',str_replace(home_url('/'),'',$image_url));
- $images = glob($dirname."*.jpg");
- if(isset($images[0])){
- $small_image = home_url('/').$images[0];
- }
- if(isset($images[1])) {
- $medium_image = home_url('/').$images[1];
- }
- if(isset($images[2])) {
- $large_image = home_url('/').$images[2];
- }
- switch($size) {
- case 'small':
- if(isset($small_image) && $small_image != '' ) {
- $image_src = $small_image;
- }
- else{
- $image_src = $image_url;
- }
- break;
- case 'medium':
- if(isset($medium_image) && $medium_image != '' ) {
- $image_src = $medium_image;
- }
- else{
- $image_src = $image_url;
- }
- break;
- case 'large':
- if(isset($large_image) && $large_image != '' ) {
- $image_src = $large_image;
- }
- else{
- $image_src = $image_url;
- }
- break;
- default:
- $image_src = $image_url;
- }
- return '<img src=' .$image_src . ' class="pubdoc-pdf-image"> ';
- }
- add_shortcode('getpublicationpdfimg', 'getPDFimg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement