Advertisement
brasofilo

Imprimir Custom Fields

Oct 27th, 2011
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Imprimir Custom Fields
  4.  * Onde instalar : functions.php
  5.  * Como usar : dentro do seu template, depois de:   the_content();  , colocar:   imprimeCF($post->ID);
  6.  * Este código em ação : http://curtaminas.com.br/acervo/2009/a-falta-que-me-faz/
  7.  */
  8.  
  9. function imprimeCF($id){
  10.     $id = intval($id);
  11.    
  12.     // Se existe este custom field ('Diretor'), então executa a impressão
  13.     if(get_post_meta($id, 'Diretor', true)!="")
  14.     {
  15.         echo '<b>Diretor/a</b>: ' . get_post_meta($id, 'Diretor', true);
  16.         echo '<br><br><b>Gênero</b>: ' . get_post_meta($id, 'Genero', true);
  17.         echo '<br><br><b>Ano</b>: '  . get_post_meta($id, 'Ano', true);
  18.         echo '<br><br><b>Tempo</b>: ' . get_post_meta($id, 'Tempo', true).'\'';
  19.         echo '<br><br><b>Ficha Técnica</b>: ' . get_post_meta($id, 'FichaTecnica',true);
  20.         echo '<br><br><b>Carreira</b>: ' . get_post_meta($id, 'Carreira', true);
  21.         echo '<br><br><b>Fomento</b>: ' . get_post_meta($id, 'Fomento', true);
  22.         echo '<br><br><b>Conservação</b>: ' . get_post_meta($id, 'Conserva', true);
  23.        
  24.         // só imprime se existir o CF 'Telefone'
  25.         if(get_post_meta($id, 'Telefone', true)!="") echo '<br><br><b>Telefone</b>: ' . get_post_meta($id, 'Telefone', true);
  26.        
  27.         // este CF pode ter duas Urls separadas por virgula (www.tal.com,www.como.com)
  28.         if(get_post_meta($id, 'www', true)!="")
  29.         {
  30.             $pizza  = get_post_meta($id, 'www',true);
  31.             $pieces = explode(",", $pizza);
  32.             echo '<br><br><a href="http://'.$pieces[0].'">'.$pieces[0].'</a>';
  33.             if($pieces[1]) echo '<br><br><a href="http://'.$pieces[1].'">'.$pieces[1].'</a>';
  34.         }
  35.        
  36.         // idem pro email
  37.         if(get_post_meta($id, 'Email', true)!="")
  38.         {
  39.             $pazza  = get_post_meta($id, 'Email',true);
  40.             $paeces = explode(",", $pazza);
  41.             if($paeces[0]) echo '<br><br>'.encode_email($paeces[0]);
  42.             if($paeces[1]) echo '<br><br>'.encode_email($paeces[1]);
  43.            
  44.         }
  45.    
  46.         // aqui se buscam todos os attachments do post/pagina e imprime conforme o tipo
  47.         $img = array();
  48.         $results = get_children( array(
  49.             'post_parent' => $id,
  50.             'post_status' => 'inherit',
  51.             'post_type' => 'attachment',
  52.             'order' => 'ASC',
  53.             'orderby' => 'menu_order ID') );
  54.  
  55.         // os $results contem muita informação, aqui a gente limpa e pega só a URL
  56.         foreach ( $results as $imagem )
  57.         {
  58.             $img[] = $imagem->guid;
  59.         }
  60.  
  61.         // conferir cada URL
  62.         foreach ($img as $att)
  63.         {
  64.             $jpgs = array();
  65.             $video = strpos($att, ".mp4"); // confere se a URL contém a string ".mp4"
  66.             $zip = strpos($att, ".zip");
  67.             $jpg = strpos($att, ".jpg");
  68.  
  69.             if ($zip !== false) {
  70.                 echo '<br><br><a href="'.$att.'">Download do Press Kit</a>';
  71.             }
  72.             if ($video !== false) {
  73.                 echo '<br><br><a href="'.$att.'">Download do Vídeo</a>';
  74.             }
  75.            
  76.             // não tenho certeza de como funciona este código pra imprimir as imagens.... :o/
  77.             if ($jpg !== false) {
  78.                 $jpgs[] = $att;
  79.                 foreach($jpgs as $jj)
  80.                 {
  81.                     echo '<br><br><img src="'.$jj.'" />';
  82.                 }
  83.             }
  84.         }  
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement