WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding The Loop Above the Header Makes Every Post the Same (3 posts)

  1. Vendetta
    Member
    Posted 4 years ago #

    Greetings,

    Amateur Web developer here so please forgive me if I get the vocabulary wrong.

    I'm trying to add a "query_posts" function above the header on my site to call some custom fields for a particular category. Here's the code:

    <?php query_posts("showposts=1&category_name=Headline"); ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <?php	$values = get_post_custom_values("Headline");
    	if (isset($values[0])) { ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><span class="headline">
    			<?php
    			$values = get_post_custom_values("Headline"); echo $values[0]; ?></span></a>
          		<?php } ?>
    
    		<?php endwhile; ?>	<br />
    
    		<?php query_posts("showposts=1&offset=1&category_name=Headline"); ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    		<?php	$values = get_post_custom_values("Headline");
    			if (isset($values[0])) { ?>
         		<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><span class="headline2">
    			<?php
    			$values = get_post_custom_values("Headline"); echo $values[0]; ?></span></a>
          		<?php } ?>
    
    		<?php endwhile; ?>

    In this case, I'm trying to call the value for "Headline" for the first two posts in the "Headline" category. The information is called and displayed correctly. However, all of the permalinks on the page now point to the last post in the "Headline" category.

    What am I doing wrong?

  2. Vendetta
    Member
    Posted 4 years ago #

    Well, I'm not sure if I'm doing anything wrong. I just moved the code out of the header and onto the index.php file and everything works fine. So I'm assuming you can't query_posts in a header that's being called with the get_header function?

  3. Vendetta
    Member
    Posted 4 years ago #

    Nevermind! I just have to use the reset_query command. Awesome!

Topic Closed

This topic has been closed to new replies.

About this Topic