20

Nov 2010


Tricks of the Trade


ifelse

For whatever reason the majority of this post disappeared on me. Luckily I was able to salvage this little bit below. Sorry about the rest.

Single Post with an Archive ontop

Okay this one made me go crazy trying to figure it out. It’s just as difficult to explain what the problem was. Okay… So I wanted to have an archive of a specific category at the top of a single post entry. This meant that in my “single.php” file I had to put a query at the top then rewind the loop at the bottom and and have it pull the single post’s information. Confused? Yeah me too.

Here is what you have to do. First you have to put in a little snippit of code to have the single post’s query saved. You do this by writting in:

1
<?php $temp_query = $wp_query; ?>

Then you do your query for the archives you want to display along with the loop:

1
2
3
4
<?php $wp_query = $temp_query; ?>
<?php while (have_posts()) : the_post(); ?>
 <!-- CONTENT GOES HERE -->
<?php endwhile; ?>

Now that you have your archives set up and the single posts query saved we can now call it;

And booyakasha you are done! Congrats!

Hopefully this post can help you out with whatever your wordpress task may be. Till next time.



Leave a Comment