• Resolved Vendetta

    (@vendetta)


    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?

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

    (@vendetta)

    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?

    Thread Starter Vendetta

    (@vendetta)

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding The Loop Above the Header Makes Every Post the Same’ is closed to new replies.