Advertisement
deadhead1971

Function to use PDF thumbnails within Toolset

Jul 25th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. function getPDFimg($atts) {
  2.              
  3.              extract( shortcode_atts( array(
  4.             'size'=>'full',
  5.         ), $atts ) );
  6.              
  7.             $image_url = str_replace(".pdf", "-pdf.jpg", types_render_field( "document-file", array('output'=> 'raw'))); // publication_document = your field name
  8.             $dirname = str_replace('.jpg','',str_replace(home_url('/'),'',$image_url));
  9.             $images = glob($dirname."*.jpg");
  10.             if(isset($images[0])){
  11.                         $small_image = home_url('/').$images[0];
  12.             }
  13.             if(isset($images[1])) {
  14.                         $medium_image = home_url('/').$images[1];
  15.             }
  16.             if(isset($images[2])) {
  17.                         $large_image = home_url('/').$images[2];
  18.             }
  19.              
  20.             switch($size) {
  21.                         case 'small':
  22.                                     if(isset($small_image) && $small_image != '' ) {
  23.                                                 $image_src = $small_image;      
  24.                                     }
  25.                                     else{
  26.                                                 $image_src = $image_url;
  27.                                     }
  28.                         break;
  29.                          
  30.                         case 'medium':
  31.                                     if(isset($medium_image) && $medium_image != '' ) {
  32.                                                 $image_src = $medium_image;  
  33.                                     }
  34.                                     else{
  35.                                                 $image_src = $image_url;
  36.                                     }
  37.                         break;
  38.                          
  39.                         case 'large':
  40.                                     if(isset($large_image) && $large_image != '' ) {
  41.                                                 $image_src = $large_image;      
  42.                                     }
  43.                                     else{
  44.                                                 $image_src = $image_url;
  45.                                     }
  46.                         break;
  47.                          
  48.                         default:
  49.                                     $image_src = $image_url;
  50.                                                  
  51.             }
  52.              
  53.     return '<img src=' .$image_src  . ' class="pubdoc-pdf-image"> ';
  54. }
  55.  
  56. add_shortcode('getpublicationpdfimg', 'getPDFimg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement