Suporte » Temas e templates » Break a Loop

  • Resolvido ninja_corp

    (@ninja_corp)


    Companheiros,

    Tenho um loop com 6 posts, o qual quero interromper para inserir um banner de publicidade. Se é que me estou a fazer entnder!

    <?php
    	//The my query --> 6 post por página da categoria ultimas
    	$my_query = new WP_Query('category_name=ultimas&posts_per_page=6'); ?>
    
    		<?php if (have_posts()) : ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    				<div class="PostHomePage2">
    					<div class="allPostContent">
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2>
    					<small><?php the_time(__('F jS, Y', 'kubrick')) ?> <!-- by <?php the_author() ?> --></small>
    
    					<div class="entry">
    						<?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?>
    					</div>
    
    					<p class="postmetadata"><?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?>  <?php comments_popup_link(__('No Comments »', 'kubrick'), __('1 Comment »', 'kubrick'), __('% Comments »', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?></p>
    				</div>
    			</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries', 'kubrick')) ?></div>
    			<div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;', 'kubrick')) ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center"><?php _e('Not Found', 'kubrick'); ?></h2>
    		<p class="center"><?php _e('Sorry, but you are looking for something that isn’t here.', 'kubrick'); ?></p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>

    Como faço para qeuebrar um loop no 3º post (por exemplo), mostrar um qualquer HTML, e depois continuar com o flow de posts?

    Alguém me pode ajudar?

A visualizar 4 respostas - de 1 a 4 (de um total de 4)
A visualizar 4 respostas - de 1 a 4 (de um total de 4)
  • O tópico ‘Break a Loop’ está fechado a novas respostas.