Title: Problem when looping posts
Last modified: August 20, 2016

---

# Problem when looping posts

 *  [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * (@kuzkuz86)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/)
 * Hello,
 * I run several using sites on wordpress and I have a major problem. When creating
   a template that loops posts (or should so), it only loops the page. I tried on
   two different setup’s with two different templates – one being zbench, so there
   shouldn’t be any problem.
 * I tried the sample codes from the wordpress tutorial on creating a loop template.
   A friend of mine also helped me, and he couldn’t solve it.
 * The page being shown, is the page that uses the loop-template.
 * Have anyone had this issue or heard of it before? I’m really desperate on getting
   it fixed 😀
 * Thanks in advance!

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

 *  Thread Starter [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * (@kuzkuz86)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565034)
 * Example: [http://godgriner.dk/loop/](http://godgriner.dk/loop/)
 * Using this template:
 * _[code moderated per [forum rules ](http://codex.wordpress.org/Forum_Welcome#Posting_Code)-
   please use the [pastebin](http://pastebin.com/)]_
 *  [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * (@justingreerbbi)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565036)
 * The loop is working perfectly fine.. I have tested the code above and it is correct
 * How many posts posts do you have
 *  Thread Starter [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * (@kuzkuz86)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565039)
 * I have over 100. So it’s serverside?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565040)
 * if this is a page template, you need to tell the loop to show anything else than
   the page – for instance by adding a a query before the loop:
 * [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  Thread Starter [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * (@kuzkuz86)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565041)
 * Could you give me an precise example of a query and tell me where to add it in
   the example code?
 * I’m guessing something like this `query_posts( 'posts_per_page=5' );` But where
   should it go?
 *  [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * (@justingreerbbi)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565042)
 * alchymyth hit it on the spot. I put the code in a index file and you have it 
   as a template.
 *  Thread Starter [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * (@kuzkuz86)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565043)
 * And yes – it’s a page template, but of course i want it to loop posts 🙂
 *  Thread Starter [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * (@kuzkuz86)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565044)
 * I don’t get it. The wordpress tutorial on making a template with a loop, doesn’t
   say anything about this 😛 Where to put the query? I’m not very gifted when it
   comes to programming, so a precisely example would be greatly appreaciated 🙂
 *  Thread Starter [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * (@kuzkuz86)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565049)
 * I have one last question. If I want to sort the posts by rating or views (wp-
   postviews and wp-postratings). How should the query-string look like then?

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

The topic ‘Problem when looping posts’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 3 participants
 * Last reply from: [sockguy](https://wordpress.org/support/users/kuzkuz86/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/problem-when-looping-posts/#post-2565049)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
