18 How to control the number of posts displayed in label pages
October 03, 2007 /

By default, the 20 most recent posts are displayed on label pages (ie: when you click on a label link in the sidebar. If there are more than 20 posts assigned to a label, then at the bottom of the page you would also find links to next and previous pages.

Recently a reader asked how it is possible to change this, particularly in regard to label clouds. So in this post, I will explain the methods for changing the number of posts displayed, for both default label lists and label clouds too.

To change the number of posts shown on label pages involves editing your template and adding some code which controls the number of posts displayed. It is always good practice to make a full back up of your blog template before making any modifications to the template, so be sure to have done this before implementing this hack!

The process is different depending on whether you use a default label list or a label cloud to display your labels, so I will explain each of these separately for you.

For default label "lists"

By "label lists" I refer to the default label widget which is generated when you add a label widget to your blog in the layouts section of your dashboard. This may be a regular list, drop down list or multi-styled version.

Decide on the number of posts you would like to be displayed in your label pages, whether this be 5 posts or 100 (see below for more details about this). Then ensure you have ticked the "expand widget templates" box. You then need to replace every occurrence of this phrase:

data:label.url
With this instead:
data:label.url + "?max-results=n"
where "n" is the number of posts you would like to display on label pages. An easy way to search for all these phrases is to key CTRL+F. You may also like to copy all of the expanded template to Notepad (or your favorite text editor) and change these phrases using the "replace" function instead. Then you would need to paste the modified template over the existing template.

Once you've done this, save your template and click on a label to see the change in the number of posts which are displayed.

For Label Cloud users.

By "Label Clouds" I refer to the hack developed by Phydeaux to display your labels in cloud form. You can read about this hack in this post, and will often find label clouds in my templates.

To change the number of posts displayed when readers click on an item in your label cloud, find this line in your template:

a.href = lcBlogURL+'/search/label/'+encodeURIComponent(t);
And replace it with this instead:
a.href = lcBlogURL+'/search/label/'+encodeURIComponent(t) +'?max-results=n';
where "n" is the number of posts you would like to be shown on labels pages. This section of code will usually appear in the section for the label widget code in your sidebar.

Save your template, and then click on an item in your label cloud to see the change in the number of items.

If you would also like the same number of posts to appear when you click on a label link from your post (usually found in the post-footer section), you would also need to replace all occurrences of "data:label.url" as described above.

Why you may want to change the number of posts displayed.

If you write particularly long posts, you may prefer to have fewer than 20 posts displayed on label pages which would speed up page loading time slightly, and also ensure the pages are not too long.

Those who use hacks to summarize their posts on the main pages (eg: the selective expandable posts hack) may wish to display more posts than 20 to fill up more space on the page instead.

Technorati Tags: | |

18 Comments:

5 July 2008 22:52 Bridey said...

Thanks again!

27 July 2008 14:19
Shafart said...

Thanks for the tip...

29 August 2008 04:05 Jose Sinclair said...

Great fix! it works... and you can use a higher number like I did (100) for small posts, or a smaller number if you have giant posts!

good stuff! -- the Jman...
http://1000dvds.blogspot.com
(now you see why I needed this!)

9 September 2008 21:06 Suzanne said...

thank you so much

14 October 2008 01:39 kakk said...

your r just great. it helped me a lot

2 November 2008 06:13 krkeans2001 said...
This post has been removed by the author.
2 November 2008 06:17 krkeans2001 said...

Lot's of thanks to you Maam Amanda! This is such a very nice post and it helps me a lot... But how about if I want to control the number of post being displayed in my blogsite archive page, is it also possible Maam??? Your help is highly appreciated...TY AGAIN

http://krkeans2001.blogspot.com

12 February 2009 14:42 Brad Farless said...

Worked great! Thanks!

16 March 2009 21:12 .: G :. said...

And how could I change the number of post displayed in the "homepage" of the blog?

Thanks in advance,

.: G :.

17 March 2009 10:55 Cool said...

Hi Amanda. Thanks for the code, but for me it's not working. Can you help me please? It shows all my post. I'd like to show only 5 posts in label page.It's here korondi.blogspot.com Help me please.

2 April 2009 14:06 Saku said...

Hey Amanda,

How can i add two label categories i.e.,

Online Games:

Arcade
Puzzle
Management
..........
........
........

and

Download Games:

Action
Arcade
Puzzle
Kids
Tycoon
.........
.........

like this i want to add two different label categories online and Download Games...

How can i add?

My blog: http://saku-games.blogspot.com/

I want like this blog:

http://www.gamezlinks.net/

Please help me Amanda, it's Urgent

Thanks in Advance

7 April 2009 12:22 akskhanbl said...

you are really a genius
thanks again

8 April 2009 07:55 rio safri said...

Thank for the code, but my label only show 4, actually I have 5 label. I wanna show all my label. Could you help me please!

10 June 2009 18:11 Tech Dockets said...

Hello,


I would like to thank you for your useful work. This would be great help for all bloggers.

16 October 2009 09:33 Chantha said...

hi all, i would like to show 1 2 3 4.. in label.

Please help me and send to chantha_reksmy@yahoo.com or check my blog http://ecamboodia.blogspot.com

wait answer from all of you.

1 November 2009 07:27 Bangambiki said...

It worked on my blog. Thx http://www.althotgirls.com

14 April 2010 08:52 Big Will said...

thanks so much, this worked for me very well. very useful info. thanks again

Post a Comment

Browse through the Archives

All existing posts are still available to view while I'm working on the site, albeit seen in a much simpler interface. Feel free to browse through the archives to find tutorials, templates and articles to help you build a better blog:

Blog Archive

© Blogger Buster 2010 Home | About | Contact | Hire Me