Suporte » Desenvolvendo com WordPress » Condição para alternar the_excerpt() e the_content()

  • Resolvido planetafm

    (@planetafm)


    Amigos, preciso da vossa ajuda. Estou a mudar o tema do meu blog. O que vou usar na Home aparece apenas o “excerpt” (na home.php) e preciso que na Home alguns posts(consoante as categorias) apareça o excerto [the_excerpt()]ou o conteúdo completo[the_content()]. Por exemplo, se for de qualquer outra categoria irá parecer apenas o excerto. Já se for da categoria “vídeo” ou “imagem” quero que na Home apareça o conteúdo completo.
    Deixo-vos abaixo o código respectivo:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    						<div id="post-<?php the_ID(); ?>" <?php post_class('block-item-big'); ?>>
    							<?php
    							if(has_post_format('video') || has_post_format('audio') || has_post_format('gallery')) {
    								$icon = '<span class="' . get_post_format($post->ID) . '-icon"></span>';
    							} else {
    								$icon = '';
    							}
    							?>
    							<?php if(has_post_thumbnail()): ?>
    							<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?>
    							<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='150' height='150' /></a><?php echo $icon; ?></div>
    							<?php else: ?>
    							<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=150&h=150" alt="<?php the_title(); ?>" width='150' height='150' /></a><?php echo $icon; ?></div>
    
    							<?php endif; ?>
    							<span class="block-meta">
    							<h4><?php the_category(', ') ?></h4>
    							</span>
    							<h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2>
    														<span class="block-meta">
    								<span class="heading-author"><?php the_author(); ?></span>
    								<span class="heading-date"><?php the_time('F j, Y'); ?></span>
    								<span class="heading-comments"><?php comments_popup_link('0','1','%'); ?></span>
    							</span>
    							<p><?php echo string_limit_words(get_the_excerpt(), 32); ?></p><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>' class="readmore"><?php _e('Ler artigo', 'Avenue'); ?> <span class="block-arrows">&raquo;</span></a>
    
    						</div>
    						<?php endwhile; endif; ?>

    Será que me podem ajudar?
    Abraços

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • Moderador Míriam de Paula

    (@miriamdepaula)

    Olá!

    Você pode usar a função in_category() para verificar qual a categoria do post.

    http://codex.wordpress.org/Function_Reference/in_category#Examples

    Criador do tópico planetafm

    (@planetafm)

    Miriam, mas eu não entendo muito de código… Por isso enviei o código:

    <p><?php echo string_limit_words(get_the_excerpt(), 32); ?></p><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>' class="readmore"><?php _e('Ler artigo', 'Avenue'); ?> <span class="block-arrows">&raquo;</span></a>

    Como faço para colocar!? Imagina que na categoria “normal” eu quero com the_excerpt() e na categoria “imagem” eu quero the_content()

    Obrigado

    Moderador Míriam de Paula

    (@miriamdepaula)

    Bom, seria algo mais ou menos assim, veja:

    <?php if( in_category('normal') ): //se na categoria "normal", permanece o código atual ?>
    
    <p><?php echo string_limit_words(get_the_excerpt(), 32); ?></p>
    <a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>' class="readmore"><?php _e('Ler artigo', 'Avenue'); ?> <span class="block-arrows">»</span></a>
    
    <?php elseif( in_category('imagem') ): // se na categoria "imagem", mostra o conteúdo completo ... ?>
    
    <?php the_content() ?>
    
    <?php endif; ?>

    Veja se funciona aí.. Qualquer coisa é só chamar! =)

    Abs.
    Miriam de Paula

Visualizando 3 respostas - 1 até 3 (de um total de 3)
  • O tópico ‘Condição para alternar the_excerpt() e the_content()’ está fechado para novas respostas.