Captain Comic
Captain Comic

Reputation: 16196

How to limit number of posts in index.php

I have an index.php with loop

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

// render post here

<?php endwhile; ?>

<?php endif; ?>

Now I want to limit number of post by N on the page and create a link to next/previous N posts.

A small code snippet is very appreciated.

UPDATE

What about the URL string? I want to make functionality similar to SO where query is determined by URL for example

get next twenty questions from the recent

https://stackoverflow.com/questions?page=2&sort=active

Upvotes: 0

Views: 3464

Answers (1)

Ignacio
Ignacio

Reputation: 8035

You can achieve that in this way:

query_posts( 'posts_per_page=5' );

References: http://codex.wordpress.org/Function_Reference/query_posts http://codex.wordpress.org/Class_Reference/WP_Query

Upvotes: 2

Related Questions