Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Imprimir Custom Fields
- * Onde instalar : functions.php
- * Como usar : dentro do seu template, depois de: the_content(); , colocar: imprimeCF($post->ID);
- * Este código em ação : http://curtaminas.com.br/acervo/2009/a-falta-que-me-faz/
- */
- function imprimeCF($id){
- $id = intval($id);
- // Se existe este custom field ('Diretor'), então executa a impressão
- if(get_post_meta($id, 'Diretor', true)!="")
- {
- echo '<b>Diretor/a</b>: ' . get_post_meta($id, 'Diretor', true);
- echo '<br><br><b>Gênero</b>: ' . get_post_meta($id, 'Genero', true);
- echo '<br><br><b>Ano</b>: ' . get_post_meta($id, 'Ano', true);
- echo '<br><br><b>Tempo</b>: ' . get_post_meta($id, 'Tempo', true).'\'';
- echo '<br><br><b>Ficha Técnica</b>: ' . get_post_meta($id, 'FichaTecnica',true);
- echo '<br><br><b>Carreira</b>: ' . get_post_meta($id, 'Carreira', true);
- echo '<br><br><b>Fomento</b>: ' . get_post_meta($id, 'Fomento', true);
- echo '<br><br><b>Conservação</b>: ' . get_post_meta($id, 'Conserva', true);
- // só imprime se existir o CF 'Telefone'
- if(get_post_meta($id, 'Telefone', true)!="") echo '<br><br><b>Telefone</b>: ' . get_post_meta($id, 'Telefone', true);
- // este CF pode ter duas Urls separadas por virgula (www.tal.com,www.como.com)
- if(get_post_meta($id, 'www', true)!="")
- {
- $pizza = get_post_meta($id, 'www',true);
- $pieces = explode(",", $pizza);
- echo '<br><br><a href="http://'.$pieces[0].'">'.$pieces[0].'</a>';
- if($pieces[1]) echo '<br><br><a href="http://'.$pieces[1].'">'.$pieces[1].'</a>';
- }
- // idem pro email
- if(get_post_meta($id, 'Email', true)!="")
- {
- $pazza = get_post_meta($id, 'Email',true);
- $paeces = explode(",", $pazza);
- if($paeces[0]) echo '<br><br>'.encode_email($paeces[0]);
- if($paeces[1]) echo '<br><br>'.encode_email($paeces[1]);
- }
- // aqui se buscam todos os attachments do post/pagina e imprime conforme o tipo
- $img = array();
- $results = get_children( array(
- 'post_parent' => $id,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'order' => 'ASC',
- 'orderby' => 'menu_order ID') );
- // os $results contem muita informação, aqui a gente limpa e pega só a URL
- foreach ( $results as $imagem )
- {
- $img[] = $imagem->guid;
- }
- // conferir cada URL
- foreach ($img as $att)
- {
- $jpgs = array();
- $video = strpos($att, ".mp4"); // confere se a URL contém a string ".mp4"
- $zip = strpos($att, ".zip");
- $jpg = strpos($att, ".jpg");
- if ($zip !== false) {
- echo '<br><br><a href="'.$att.'">Download do Press Kit</a>';
- }
- if ($video !== false) {
- echo '<br><br><a href="'.$att.'">Download do Vídeo</a>';
- }
- // não tenho certeza de como funciona este código pra imprimir as imagens.... :o/
- if ($jpg !== false) {
- $jpgs[] = $att;
- foreach($jpgs as $jj)
- {
- echo '<br><br><img src="'.$jj.'" />';
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement