Display any Number of Posts in a Loop

Posted by ADMIN On 4:32 AM
Did you ever want to display a different number of posts on different pages. For example
on your category pages, you want to display 10 posts which you can control from your
Admin panel, but another page you want to show only 5 posts. Well this tutorial is just for you.

Open a Template file where you want to display an x number of recent posts:

    // if everything is in place and ready, let’s start the loop

    // to display ‘n’ number of posts, we need to execute the loop ‘n’ number of times
    // so we define a numerical variable called ‘$count’ and set its value to zero
    // with each iteration of the loop, the value of ‘$count’ will increase by one
    // after the value of ‘$count’ reaches the specified number, the loop will stop
    // *USER: change the ‘n’ to the number of posts that you would like to display


    if ($count == "n") { break; }
    else { ?>

    // for CSS styling and layout purposes, we wrap the post content in a div
    // we then display the entire post content via the ‘the_content()’ function
    // *USER: change to ‘‘ to display post excerpts instead

    // here, we continue with the limiting of the number of displayed posts
    // each iteration of the loop increases the value of ‘$count’ by one
    // the final two lines complete the loop and close the if statement

0 Response to "Display any Number of Posts in a Loop"

Post a Comment

Google Translator

Search Box

Blog Archive

User Status

Free counters!

About Me

ADMIN
Pakistan
View my complete profile

Recent Posts

Recent Comments