Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

my single post looks like that: http://pastebin.com/KdEbs82P

I want to display on single post two things:

  • list of ALL posts in general
  • single post title
  • content

What I achieved right now is not satisfing because I AM displaying all posts (and it works ok) but the second part (connected with showing only specific post title and content) don't work. By don't work I mean - it shows only the newest one;/ So giving it into real example:

I have 2 posts called "News about IT" and "TV series". Post about TV is the newest one. After clicking on News about IT i will see all posts in the top and as a main part - title and content of NEWS ABOUT IT. Right now using my solution it shows TV series as a newest post..

how to achieve my solution?

share|improve this question
    
Please include your code in the question itself. If that pastebin links breaks the question become meaningless. –  s_ha_dum Feb 17 '13 at 15:58

1 Answer 1

When the single post template is loaded, WordPress has already queried the database for that post. When you call query_posts('post_type=post&posts_per_page=1');, and then run the loop, this simply loads and outputs a single post, which by default will be the latest post. It also has the side-effect of overwriting the original main query.

You don't need to, nor should you ever call query_posts in the template.

To load additional posts beside the single post you are currently viewing, use WP_Query, and leave the main query unaltered.

// load and display all posts
// setting post_type is unnecessary, it will default to post
$all_posts = new WP_Query( array( 'posts_per_page' => -1 ) );
while( $all_posts->have_posts() ):
    $all_posts->the_post();
    // your markup for all posts
endwhile;

// reset the global post variable
wp_reset_postdata();

// now output the single post
// no need for a query, the post data already exists
// in the global $wp_query
while( have_posts() ):
    the_post();
    // your markup for the single post
endwhile;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.