Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Chirlison

Limpar o the_content();

Recommended Posts

Bom dia a todos!

Pessoal, sou iniciante em Wordpress e estou com o seguinte problema.

Como eu poderia limpar o the_content();?

 

Meu código está da seguinte forma:

No primeiro código eu pego a postagem de uma página.

No segundo código eu pego a postagem de uma galeria que está na categoria institucional, mas na postagem da galeria eu tenho apenas o shortcode da galeria e com isso está imprimindo o mesmo conteúdo da postagem da página, ou seja, a galeria é apresentada, mas a postagem da página está se repetindo.

 

Vejam como está meu código:

//Aqui eu pego a postagem da página 
<div>
               <?php $institucional = new WP_Query( 'pagename=institucional' ); ?>
               
                <?php if( $institucional->have_posts() ) : $institucional->the_post(); ?>
                
                <?php the_content(); ?>
                
                <?php endif; ?>
</div>
 
<div> 
//Aqui eu pego o conteúdo do post da galeria que está na categoria institucional  
                   <?php query_posts('category_name=institucional&offset=0&showposts=1'); ?>
                   
                   <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
                                    
                    <?php the_content(); ?>
                    
                    <?php endwhile; else: ?>
                    <?php endif; ?>

</div> 

Desde já, agradeço a todos que tentarem me ajudar.

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

mruoppolo, obrigado por responder, mas infelizmente o site está local, não tenho o site no ar.

Estou desenvolvendo o site localmente para depois colocar no ar.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ja tentou retirar o laço de repetição??

 

substituir

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
                                    
        <?php the_content(); ?>
                    
<?php endwhile; else: ?>
<?php endif; ?>

por

<?php the_content(); ?>

???

Compartilhar este post


Link para o post
Compartilhar em outros sites

O texto abaixo da imagem é uma página.

Criei uma categoria chamada institucional e criei um post com o shortcode de uma galeria.

Ao imprimir o conteúdo do post onde está a galeria, o texto da página está se repetindo.

 

Veja o código novamente:

 

 

//Aqui eu pego a postagem da página 
<div>
               <?php $institucional = new WP_Query( 'pagename=institucional' ); ?>
               
                <?php if( $institucional->have_posts() ) : $institucional->the_post(); ?>
                
                <?php the_content(); ?>
                
                <?php endif; ?>
</div>
 
<div> 
//Aqui eu pego o conteúdo do post da galeria que está na categoria institucional 
                   <?php query_posts('category_name=institucional&offset=0&showposts=1'); ?>
                   
                   <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
                                    
                    <?php the_content(); ?>
                    
                    <?php endwhile; else: ?>
                    <?php endif; ?>

</div> 

 

VIqZOe.jpg

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ao invés de usar o query_posts, tente o usar o get_posts ou o WP_Query igual fez na parte de cima. Query Posts são problemáticos.

 

E na verdade bixo, ao invés de usar o WP_Query na parte de cima, você deveria utilizar a query padrão da page.php, só que no seu page.php você coloca abaixo uma tag condicional IS_PAGE chamando o conteúdo da categoria em WP_Query.


Tenta colocar assim na sua page.php

//Aqui eu pego a postagem da página 
<div>
                <?php if(have_posts() ) : the_post(); ?>
                                   <?php the_content(); ?>                                
                <?php endif; ?>
</div>
 
<div> 
//Aqui eu pego o conteúdo do post da galeria que está na categoria institucional 
<?php if (is_page(ID_DA_PÁGINA_INSTITUCIONAL)) : ?>
                  <?php
                    global $post;
                    $args = 'category=ID_DA_CATEGORIA_INSTITUCIONAL';
                    $myposts = get_posts( $args );
                    foreach( $myposts as $post ) :    setup_postdata($post); ?>
                                             <?php the_content(); ?>
                    <?php endforeach; ?>
<?php endif;?>
</div> 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Muito obrigado, LastK!

Funcionou perfeitamente.

 

Veja o código final como ficou:

 

 

//Aqui eu pego a postagem da página 
<div>
                <?php $institucional = new WP_Query( 'pagename=institucional' ); ?>
                <?php if( $institucional->have_posts() ) : $institucional->the_post(); ?>              
                <?php the_content(); ?>                
                <?php endif; ?>
</div>
 
<div> 
//Aqui eu pego o conteúdo do post da galeria que está na categoria institucional 
<?php if (is_page(ID_DA_PÁGINA_INSTITUCIONAL)) : ?>
                  <?php
                    global $post;
                    $args = 'category=ID_DA_CATEGORIA_INSTITUCIONAL';
                    $myposts = get_posts( $args );
                    foreach( $myposts as $post ) :    setup_postdata($post); ?>
                                             <?php the_content(); ?>
                    <?php endforeach; ?>
<?php endif;?>
</div> 

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.