• Hi!
    I’m going crazy here right now. I have a problem with my start loop, that wants to show the content twice. Is there anyone that knows why this problem occurs?

    Here’s my code:

    <!--<div class="spacer"></div>
    <div class="content transparent">
    <div class="content-inner">
     <h1><strong>Header</strong></h1>
    </div></div>-->
    
     <?php if (in_category('sticky')) { ?>
        <div class="content transparent splash"><?php the_post_thumbnail( 'full', array( 'class' => 'hundred-width' ) ); ?>
        <div class="intro"><h1><strong><?php the_title(); ?></strong></h1>
        <h2><?php the_field('ingress'); ?></h2>
        <?php the_content(); ?></div></div>
    
    <?php } else {?>
    
    <article id="post-<?php the_ID(); ?>">
    <div class="content-inner transparent animatedParent animateOnce data-appear-top-offset='30'">
    <div class="two-column-left-img animated fadeInDownShort go">
    	<?php
    		// Post thumbnail.
    		the_post_thumbnail( 'large', array( 'class' => 'hundred-width' ) );
    	?>
        </div>
        <div class="two-column-right animated fadeInUpShort go">
        <h1><?php the_title(); ?></h1>
    
        <p><?php the_excerpt(); ?></p>
    
    <a class="button orange" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Läs mer</a>
    <?php } ?>
    </li>
    </ul>
    </div>
        </div>
        </div>
    
      <div class="content transparent">
    <div class="content-inner front animatedParent data-sequence='500'">
     <?php
     $counter = 1;
     $new_query = new WP_Query(array('post_type' => 'my_content'));
    while ($new_query->have_posts()) : $new_query->the_post();
    ?>
    <div class="four-column-front transparent animated fadeInUpShort go data-id='<?php echo $counter?>'">
    <div style="height: 250px; position: relative;">
    <?php the_post_thumbnail( 'large', array( 'class' => 'hundred-width' ) ); ?></div>
    <a href="<?php the_permalink(); ?>"><h4>Test<br>
    <?php the_title(); ?></h4></a></div>
    <?php
    $counter++;
    endwhile;
    wp_reset_query();?>
    <div class="clear"></div>
      </div>
    </div>  
    
        </article>
    
    <div class="clear"></div> 
    
    <div class="content"><div class="content-inner">
    <div class="three-column front-box l-grey animated fadeInUpShort go">
    <img class="sub-bg" src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/sub-menu/three_column_img.jpg" alt="FAQ" />
    <a class="button orange">FAQ</a></div>
    <div class="three-column front-box l-grey animated fadeInUpShort go">
    <img class="sub-bg" src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/sub-menu/three_column_img.jpg" alt="Frågor & svar" />
    <a class="button orange">Test?</a></div>
    <div class="three-column front-box l-grey animated fadeInUpShort go">
    <img class="sub-bg" src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/sub-menu/three_column_img.jpg" alt="Frågor & svar" />
    <a class="button orange">Test</a></div>
    </div></div>
    
    <?php $new_query = new WP_Query(array('post_type' => 'faq', 'orderby' => 'rand', 'showposts' => '1'));
    while ($new_query->have_posts()) : $new_query->the_post(); ?>
    
    <div class="content faq orange">
    <div class="content-inner">
    <div class="two-column-left animated fadeInLeftShort go"><h2><?php the_title(); ?></h2></div>
    
    <div class="two-column-right animated fadeInRightShort go"><?php the_content(); ?></div>
    <div class="clear"></div>
    
    <a href="/web/faq/" class="button l-grey">Läs FAQ</a></h2>
    </div>
    </div>
    <?php endwhile;
    wp_reset_query();?>
    
    <?php
    
    $new_query = new WP_Query(array('post_type' => 'quotes', 'orderby' => 'rand', 'showposts' => '1'));
    while ($new_query->have_posts()) : $new_query->the_post(); 
    
    $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
    
    <div class="parallax-fullwidth animatedParent" data-parallax="scroll" data-speed="0.5" data-image-src="<?php echo $url; ?>" data-natural-width="1500" data-natural-height="1000" data-position="0px 20px">
    <div class="content-inner">
    
    <div class="two-column-left"><h3><?php the_content(); ?></h3>
    <p><?php the_title(); ?></p>
    <a href="/web/quotes/" class="button orange">Quotes</a></h2>
    </div>
    <div class="clear"></div>
    </div>
    </div>
    <?php endwhile;
    wp_reset_query();?>
    
       <!--<?php
    			/* translators: %s: Name of current post */
    			the_content( sprintf(
    				__( 'Continue reading %s', 'betavivo' ),
    				the_title( '<span class="screen-reader-text">', '</span>', false )
    			) );
    
    			wp_link_pages( array(
    				'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'betavivo' ) . '</span>',
    				'after'       => '</div>',
    				'link_before' => '<span>',
    				'link_after'  => '</span>',
    				'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'betavivo' ) . ' </span>%',
    				'separator'   => '<span class="screen-reader-text">, </span>',
    			) );
    		?>  -->   
    
    	<!--<?php
    		// Author bio.
    		if ( is_single() && get_the_author_meta( 'description' ) ) :
    			get_template_part( 'author-bio' );
    		endif;
    	?>-->
    
    	<section class="entry-footer">
    		<!--<?php betavivo_entry_meta(); ?> -->
    
    		<?php edit_post_link( __( 'Redigera produkt →', 'betavivo' ), '<span class="edit-link">', '</span>' ); ?>
    	</section><!-- .entry-footer -->
        </div><!-- .entry-content -->
        </div>
    
    </article><!-- #post-## -->
    <?php wp_reset_postdata(); ?>

    Thank you soo much for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Corneliatt

    (@corneliatt)

    Hi!

    I forgot to show you the index file content:

    get_header(); ?>
    		<?php if ( have_posts() ) :
    		 ?>
    
    			<?php if ( is_home() && ! is_front_page() ) : ?>
    
    				<header>
    					<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
    				</header>
    			<?php endif; ?>
    <section class="spacer animatedParent animateOnce data-appear-top-offset='30'">
    			<?php
    			// Start the loop.
    			 while ( have_posts() ) : the_post();
    
    				/*
    				 * Include the Post-Format-specific template for the content.
    				 * If you want to override this in a child theme, then include a file
    				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    				 */
    				get_template_part( 'content-start', get_post_format() );
    
    			// End the loop.
    			endwhile;
    
    			// Previous/next page navigation.
    			the_posts_pagination( array(
    				'prev_text'          => __( 'Previous page', 'betavivo' ),
    				'next_text'          => __( 'Next page', 'betavivo' ),
    				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'betavivo' ) . ' </span>',
    			) );
    
    		// If no content, include the "No posts found" template.
    		else :
    			get_template_part( 'content', 'none' );
    
    		endif;
    		?>
    </section>
    <?php  get_footer(); ?>

    Nobody who knows what could be the problem here?? Have I managed to do something super weird? :S

    Thread Starter Corneliatt

    (@corneliatt)

    Hi again!
    Ok, so now I’ve got one step closer to solving this.

    The loop loops twice only when I’ve got two posts (but I just wanna show one!!). When I delete the second post, everything goes back to how it should. How do I set a limit to just ONE post on just the index page (not on the categories pages and so on). Have tried
    <?php query_posts('showposts=1'); ?>
    without any luck…

    Would be so thankful!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘My startpage loops twice’ is closed to new replies.