• Resolvido Eva Morrissey

    (@evamorrissey)


    Olá,
    Como não encontrava um tema gratuito que encaixasse exatamente no que eu quero e mesmo os comprados que tentei me deram mais dor de cabeça do que qualquer coisa, resolvi encarar o desafio de desenvolver um tema do zero. Apesar de ser designer, não entendia tanta coisa do funcionamento do WordPress, então tenho apanhado um bocado – mas está quase tudo pronto, o resto vai ser mexer mesmo em CSS.

    No momento, estou encontrando dificuldades para configurar fallback images na home. Estou usando o seguinte código no superloop (que ainda está incompleto, novas alterações virão, mas a base é esta):

    <!-- SUPERLOOP -->
    
    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $count++; ?>
    <?php if ($count == 1) : ?>
    
    <div id="boxhome1">
       <a class="linkimg" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'destaquespost' ); } // custom ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome1-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 2) : ?>      
    
    <div id="boxhome2">
       <a class="linkimg2" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } // custom ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome2-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 3) : ?> 
    
    <div id="boxhome3">
       <a class="linkimg3" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } // custom ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome3-destaque"><?php the_title(); ?></a></h2>
                    </div>     
    
    <?php elseif ($count == 4) : ?>  
    
    <div id="boxhome2">
       <a class="linkimg2" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } // custom ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome2-destaque"><?php the_title(); ?></a></h2>
                    </div>  
    
    <?php elseif ($count == 5) : ?>  
    
    <div id="boxhome3">
       <a class="linkimg3" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } // custom ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome3-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 6) : ?>
    
     <div id="boxhome1">
       <a class="linkimg" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'destaquespost' ); } // custom ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome1-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php else : ?>
    
    <div id="posts-da-home">
    <?php if ( has_post_thumbnail()) : ?>
       <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php the_post_thumbnail(); ?>
       </a>
    
     <?php endif; ?>
     <h2><a href="<?php the_permalink() ?>"><div class="posts-da-home-destaque"><?php the_title(); ?></div></a></h2>
                    </div>          
    
      <?php endif; ?>
    <?php endwhile; ?>
    <?php endif; ?>
    
    <!-- FIM DO SUPERLOOP -->

    Tentei diversos tutoriais, desde mexer no meu functions.php até adicionar um else depois do if dos thumbnails já configurados, mas tudo o que tentei causou algum erro no meu tema. Alguém pode me dar uma luz?

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • Veja se consegue com esse trecho de código:

    <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>

    Criador do tópico Eva Morrissey

    (@evamorrissey)

    Infelizmente, não funcionou :c

    Meu superloop tá assim:

    <!-- SUPERLOOP -->
    
    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $count++; ?>
    <?php if ($count == 1) : ?>
    
    <div id="boxhome1">
       <a class="linkimg" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail( 'destaquespost' );
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image-big.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome1-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 2) : ?>      
    
    <div id="boxhome2">
       <a class="linkimg2" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome2-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 3) : ?> 
    
    <div id="boxhome3">
       <a class="linkimg3" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome3-destaque"><?php the_title(); ?></a></h2>
                    </div>     
    
    <?php elseif ($count == 4) : ?>  
    
    <div id="boxhome2">
       <a class="linkimg2" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome2-destaque"><?php the_title(); ?></a></h2>
                    </div>  
    
    <?php elseif ($count == 5) : ?>  
    
    <div id="boxhome3">
       <a class="linkimg3" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome3-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 6) : ?>
    
     <div id="boxhome1">
       <a class="linkimg" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail( 'destaquespost' );
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image-big.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome1-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 7) : ?>
    
    <div id="boxhome2">
       <a class="linkimg2" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome2-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 8) : ?>
    
    <div id="boxhome3">
       <a class="linkimg3" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome3-destaque"><?php the_title(); ?></a></h2>
                    </div> 
    
    <?php elseif ($count == 9) : ?>
    
    <div id="boxhome2">
       <a class="linkimg2" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome2-destaque"><?php the_title(); ?></a></h2>
                    </div>
    
    <?php elseif ($count == 10) : ?>
    
    <div id="boxhome3">
       <a class="linkimg3" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
       </a>
     <h2><a href="<?php the_permalink() ?>" class="boxhome3-destaque"><?php the_title(); ?></a></h2>
                    </div>
    <div id="clear"></div>
    <?php else : ?>
    
    <div id="posts-da-home">
     <h2><a href="<?php the_permalink() ?>"><div class="posts-da-home-destaque"><?php the_title(); ?></div></a></h2>
    
    <?php if ( has_post_thumbnail()) : ?>
       <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php the_post_thumbnail( 'homepage-thumb' ); ?>
       </a>
    
     <?php endif; ?>
    
    <?php the_excerpt(); ?>
    
    <a href="<?php the_permalink(); ?>" title="Continue lendo <?php the_title(); ?>" class="more-link">Continue lendo »</a>
                    </div>
    
    <div id="clear"></div>
    
      <?php endif; ?>
    <?php endwhile; ?>
    <?php endif; ?>
    
    <!-- FIM DO SUPERLOOP -->

    E dá pra ver ele (não funcionando) aqui: http://teste.livrodosespelhos.com/page/2/

    As imagens estão devidamente no lugar, na pasta do tema, tudo certinho. O que estou fazendo de errado?

    Criador do tópico Eva Morrissey

    (@evamorrissey)

    Ok, problema resolvido! Por algum motivo, quando copiei os posts do blog original pra este de testes, ele copiou o fato de que havia thumbs configuradas, mas não importou as imagens, então estava dando pau nas fallback images. Muito obrigada Everaldo, sua solução funcionou depois que eu arrumei isso ^-^

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • O tópico ‘Fallback Images em tema próprio’ está fechado para novas respostas.