25 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: | |

Author: Amanda Kennedy

Amanda is a professional blogger and web designer living in Sheffield, United Kingdom.

In addition to curating Blogger Buster, you can find Amanda on Twitter, Facebook or add her to your circle on Google+.

Like to share?

You may also like to subscribe to Blogger Buster's RSS feed or receive free email updates of our latest posts.

25 Comments:

  1. Thanks for the tip...

    ReplyDelete
  2. 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!)

    ReplyDelete
  3. your r just great. it helped me a lot

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. 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

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

    Thanks in advance,

    .: G :.

    ReplyDelete
  7. 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.

    ReplyDelete
  8. 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

    ReplyDelete
  9. you are really a genius
    thanks again

    ReplyDelete
  10. 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!

    ReplyDelete
  11. Hello,


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

    ReplyDelete
  12. 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.

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

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

    ReplyDelete
  15. good tips. but how to limit number of posts displayed on archive page ?

    ReplyDelete
  16. OMG! It works! I can't believe I was able to edit HTML. That thing looks so scarry!!!
    Thank you so so so much.

    ReplyDelete
  17. I am thoroughly convinced in this said post. I am currently searching for ways in which I could enhance my knowledge in this said topic you have posted here. It does help me a lot knowing that you have shared this information here freely. I love the way the people here interact and shared their opinions too. I would love to track your future posts pertaining to the said topic we are able to read.

    ReplyDelete
  18. Thanks for taking the time to discuss this, I feel strongly about information and love learning more on this. If possible, as you gain expertise, It is extremely helpful for me. would you mind updating your blog with more information

    ReplyDelete
  19. Thank you for the information that provided.

    ReplyDelete

Great! You've decided to leave a comment! Please bear in mind that comments are often moderated and that rel="nofollow" is in use and spammy comments will be deleted. Let's have a meaningful conversation instead. Thanks for stopping by!

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