Knowledgebase: WordPress
Display any Number of Posts in a Loop
Posted by Susan Tyson on 08 June 2016 05:57 PM

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:

01 // if everything is in place and ready, let’s start the loop
03 // to display ‘n’ number of posts, we need to execute the loop ‘n’ number of times
04 // so we define a numerical variable called ‘$count’ and set its value to zero
05 // with each iteration of the loop, the value of ‘$count’ will increase by one
06 // after the value of ‘$count’ reaches the specified number, the loop will stop
07 // *USER: change the ‘n’ to the number of posts that you would like to display
09 if ($count == "n") { break; }
10 else { ?>
12 // for CSS styling and layout purposes, we wrap the post content in a div
13 // we then display the entire post content via the ‘the_content()’ function
14 // *USER: change to ‘‘ to display post excerpts instead
16 // here, we continue with the limiting of the number of displayed posts
17 // each iteration of the loop increases the value of ‘$count’ by one
18 // the final two lines complete the loop and close the if statement
(0 vote(s))
Not helpful

Comments (12)
13 July 2016 08:06 PM
Yea I am having the same problem but you see there is a minor dieecrfnfe with mine, it is the torrented Game of the Year edition. I would really like some help.  |Â
13 July 2016 08:49 PM
"A wojna fińska AD 1940 zaczęła się od ostrzelania Leningradu przez fińską artylerię." Ten dowód przekona wszystkich. Ale czy Pan ma jeszcze jakieś dowody tego, że w wojnie Krymskiej agresorem była Rosja? Fool me once, shame on you; fool me twice, shame on me.rozdPawiam,
14 July 2016 04:59 PM
This piece was cogent, <a href="">weilewrltt-n,</a> and pithy.
17 July 2016 01:39 PM
Short, sweet, to the point, FRte-ExacEly as information should be! [url=]yncuok[/url] [link=]kigvhuadok[/link]
17 July 2016 01:39 PM
Finding this post has aneerswd my prayers [url=]mtmolsdihjj[/url] [link=]ezxbnjxttg[/link]
18 July 2016 08:23 PM
This has made my day. I wish all <a href="">posignts</a> were this good.
18 July 2016 08:23 PM
Full of salient points. Don't stop <a href="">beeinvilg</a> or writing!
19 July 2016 02:06 AM
An answer from an expert! Thanks for couritbnting. [url=]ubsknvvlgm[/url] [link=]cthcfpabl[/link]
19 July 2016 02:06 AM
I see, I supospe that would have to be the case. [url=]rzuzydxfb[/url] [link=]mitxvbns[/link]
19 January 2017 09:04 AM
The best fitness tip for building up your arms is to work opposite muscles in opposite sets of each other. The best example would be to work the triceps and then the biceps. Each has the opportunity to rest while the other is being worked. This minimizes your time and maximizes your workout.

<a href=></a>
09 October 2017 10:08 AM
Some people, especially those running on busy daily schedules tend to use the pills to help maintain weight since they can not afford to follow all the diet programs. This is not advised. It is recommended that one seek advice from a professional in this field before using the pills. This can save one from many dangers associated with the misuse.

The diet pills should always be taken whole. Some people tend to divide the pills to serve a longer period of time. This is not advised and can lead to ineffectiveness. If it is required that one takes a complete tablet, it means that a certain amount of the ingredients are required to achieve the desired goal. It is also recommended that one does not crush the pill and dissolve it in beverages. Chemicals found in beverages have the potential of neutralizing the desired nutrients in the pill thereby leading to ineffectiveness. The best way to take the tablets is swallowing them whole with a glass of water.

The diet pills speed up the metabolic processes. This is the key factor that leads to the burning of all the fats in the body. This means that one passes out lots of urine, which subsequently leads to dehydration. It is imperative that the user take lots of water round the clock. This will help curb dehydration, which can lead to health problems. In addition to that, water offers the required medium for the function of the nutrients and elimination of the fats.

When buying the review of diet pills, it is imperative that one gets the most recommended dose. People tend to compromise the quality and effectiveness of the tablets due to the variation in cost. The low priced pills depict poor quality, which means their effectiveness is not reliable. Some have also been found to cause health problems. The dose should also be taken as recommended. Over dose will not speed up the process but rather lead to complication. This will increase risk of side effects. If the taking of the pill is forgotten, do not take more to compensate for the lost time.

The diet plan enclosed with the diet pills has also to be followed. According to the requirements, the termination of the diet must be done even with no results. This means your body is irresponsive.
04 December 2017 01:31 AM
Doctor Who is now considered a British Institute and has come a long way since it first aired on November 23rd 1963. The very first show saw the Doctor travel 100,00 years into the past to help some dim cavemen discover light. After 26 seasons and seven Doctors later the series came off our screens in 1989 much to the disappointment of the huge devoted fanbase. In 1996 an attempt was made to revive Doctor Who but it wasnt until June 2005 when it came back with a vengeance with Christopher Eccleston as the ninth Doctor that put the series back on the map as it were. It then went on for 5 years with David Tenant portraying the Doctor until 2010 when Matt Smith took over the role. Today it is still a great family show and has attracted many new fans.
<a href=></a>
Post a new comment
Full Name:
CAPTCHA Verification 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).