Suporte » Temas » Adicionar uma imagem padrão em post por categoria

  • Resolvido Cesar A.R de Oliveira

    (@cesar-ar-de-oliveira)


    Bom minha dúvida é como adicionar uma imagem padrão no wordpress.
    Mas não é tão simples… pois veja bem eu sei como adicionar uma imagem padrão.
    O problema é que eu quero fazer isto de uma forma que fique facil para qualquer um fazer dinamicamente.

    Tipo eu faço agora assim.

    <div id="single_img">
    
    <?php if (get('imagem_single') != '') : ?>   
    
    <?php $count_images = get_count_field($field_name = 'imagem_single', $group_index = 1, $post_id = get_the_ID()); ?>
    <?php for($i=1; $i <= $count_images; $i++) : ?>
    
      <a href="<?php echo get('imagem_single', $group_index, $i, 0, $post_id, null, null, 'full');?>" rel="lightbox[917]"><img src="<?php echo get_image('imagem_single', $group_index, $i, 0, $post_id, null, null, 'minisingle'); ?>" /></a> 
    
    <?php endfor; ?>
    
    <?php else : ?>
    <a href="<?php echo get_settings('home'); ?>/wp-content/uploads/2012/06/Pauline-Garske-boa.jpg" rel="lightbox[917]"><img src="<?php echo get_settings('home'); ?>/wp-content/uploads/2012/06/Pauline-Garske-boa.jpg" /></a> 
    
    <?php endif; ?>
    </div>

    Mas não me veem a mente um modo mais simples de fazer tudo pelo painel do wordpress.

    Tipo quero só programar uma vez e depois adicionar tudo o que for necessário via o painel do wordpress.

    Alguém tem alguma idéia ?

    Eu vou testar amanhã criar um novo bagulho de postagem só para configurar isto ou sei lá.

    obrigado desde já pela ajuda de todos.

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • Criador do tópico Cesar A.R de Oliveira

    (@cesar-ar-de-oliveira)

    que diabo, que inferno.

    Como usa a droga do else if ou sei lá eu, o que para dar mais opções nisto aqui :

    <div id="content_destaque_destaque">
                <?php query_posts('showposts=1&category_name=noticias');?>
    
                <?php if (have_posts()): while (have_posts()) : the_post();?>
    
                <span><a href="<?php the_Permalink()?>">Postado em <?php the_time('j M Y');?></a></span>
                  <a href="<?php the_Permalink()?>"><img src="<?php echo get_image('imagem_single', 1, 1, 0, get_the_ID(), null, null, 'mini350'); ?>" alt="<?php the_title();?>" width="350" height="175" border="0" /> </a>
    
    			   <?php elseif (get('imagem_single') == '' : ?>
    <a href="<?php the_Permalink()?>"><img src="<?php echo get_settings('home'); ?>/wp-content/themes/upnews/img_padrao/sem-foto-ainda-350x175.png" alt="<?php the_title();?>" width="350" height="175" border="0" /></a> 
    
                  <p><a href="<?php the_Permalink()?>"><?php the_title();?></a></p>
    
    			  <?php endwhile; elseif:?>
                  <?php endif;?> 
    
               </div><!--content_destaque_destaque-->

    Tipo eu tive a impressão de ter entendido o if else na porcaria do wordpress ou php , tanto faz .
    Mas pelo visto não entendi droga nem uma.
    Então faço para tipo.

    Quero que caso a postagem não tenha imagem ele use a imagem padrão, que coloquei aqui .

    <a href="<?php the_Permalink()?>"><img src="<?php echo get_settings('home'); ?>/wp-content/themes/upnews/img_padrao/sem-foto-ainda-350x175.png" alt="<?php the_title();?>" width="350" height="175" border="0" /></a>

    Criador do tópico Cesar A.R de Oliveira

    (@cesar-ar-de-oliveira)

    vai pro diabo que carregue auehuaheh, até que um dia consegui fazer.

    Quem quiser ficou assim

    <div id="content_destaque_destaque">
                <?php query_posts('showposts=1&category_name=noticias');?>
    
                <?php if (have_posts()): while (have_posts()) : the_post();?>
    
                <?php if (get('imagem_single') != '') { ?>
                <span><a href="<?php the_Permalink()?>">Postado em <?php the_time('j M Y');?></a></span>
                  <a href="<?php the_Permalink()?>"><img src="<?php echo get_image('imagem_single', 1, 1, 0, get_the_ID(), null, null, 'mini350'); ?>" alt="<?php the_title();?>" width="350" height="175" border="0" /> </a>
    
    			 <?php } else { ?>
                  <a href="<?php the_Permalink()?>"><img src="<?php echo get_settings('home'); ?>/wp-content/themes/upnews/img_padrao/sem-foto-ainda-350x175.png" alt="<?php the_title();?>" width="350" height="175" border="0" /></a>
                 <?php } ?>
                  <p><a href="<?php the_Permalink()?>"><?php the_title();?></a></p>
    
    			  <?php endwhile; else:?>
                  <?php endif;?>

    Ainda vou verificar , para ter certeza e já posto aqui.

    É funcionou perfeitamente.
    Eu vi como usar está bosta aqui.

    http://codex.wordpress.org/The_Loop

    O meu erro , era que eu queria usar 2 <?php endif;?>, sendo que não precisava.
    É só vocês olharem este código e vão entender:

    <!-- Start the Loop. -->
     <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
     <!-- The following tests if the current post is in category 3. -->
     <!-- If it is, the div box is given the CSS class "post-cat-three". -->
     <!-- Otherwise, the div box will be given the CSS class "post". -->
     <?php if ( in_category('3') ) { ?>
               <div class="post-cat-three">
     <?php } else { ?>
               <div class="post">
     <?php } ?>
    
     <!-- Display the Title as a link to the Post's permalink. -->
     <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
     <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
     <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
    
     <!-- Display the Post's Content in a div box. -->
     <div class="entry">
       <?php the_content(); ?>
     </div>
    
     <!-- Display a comma separated list of the Post's Categories. -->
     <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
     </div> <!-- closes the first div box -->
    
     <!-- Stop The Loop (but note the "else:" - see next line). -->
     <?php endwhile; else: ?>
    
     <!-- The very first "if" tested to see if there were any Posts to -->
     <!-- display.  This "else" part tells what do if there weren't any. -->
     <p>Sorry, no posts matched your criteria.</p>
    
     <!-- REALLY stop The Loop. -->
     <?php endif; ?>
    Criador do tópico Cesar A.R de Oliveira

    (@cesar-ar-de-oliveira)

    <div id="content_destaque_destaque">
                <?php query_posts('showposts=1&category_name=noticias');?>
    
                <?php if (have_posts()): while (have_posts()) : the_post();?>
    
                <?php if (get('imagem_single') != '') { ?>
                <span><a href="<?php the_Permalink()?>">Postado em <?php the_time('j M Y');?></a></span>
                  <a href="<?php the_Permalink()?>"><img src="<?php echo get_image('imagem_single', 1, 1, 0, get_the_ID(), null, null, 'mini350'); ?>" alt="<?php the_title();?>" width="350" height="175" border="0" /> </a>
    
    			 <?php } else { ?>
                  <a href="<?php the_Permalink()?>"><img src="<?php echo get_settings('home'); ?>/wp-content/themes/upnews/img_padrao/sem-foto-ainda-350x175.png" alt="<?php the_title();?>" width="350" height="175" border="0" /></a>
                 <?php } ?>
                  <p><a href="<?php the_Permalink()?>"><?php the_title();?></a></p>
    
    			  <?php endwhile; else:?>
                  <?php endif;?> 
    
               </div><!--content_destaque_destaque-->

    Acho que faltou o bagulho de fechar a DIV

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • O tópico ‘Adicionar uma imagem padrão em post por categoria’ está fechado para novas respostas.