Fix for Page Numbers on Labels
The page numbers widget was not showing up on the labels page so I was looking at the code. The issue was with the URL for the json script that reads the Atom feed for the labels. The page numbers script was parsing for a query string where one doesn't exist in the basic label links. It was giving a URL with the place for the label filled with the entire URL to the site.
There was a fix where the links could be changed so as to have query strings with the number per page attached, but that same fix is no longer possible in the newer themes' Label widget.
So I tried replacing part of the Label1 widget with the Label1 widget from the Picture Window theme. It did work. So I was able to change the link hrefs to include the query string.
expr:href='data:label.url'
to
expr:href='data:label.url + "?&max-results=7"'
The page numbers widget seems to be working perfectly now with that fix.
To make the page numbers show up on the first page of a label in a newer theme, with the newer Label widget, is possible. One way is, in the script, to re-parse the URL so as to get the value for the label name variable when the query string is missing.
// find out if the query string is there
if(thisUrl.indexOf("?&max")!=-1){
// this line was here:
postLabel=thisUrl.substring(thisUrl.indexOf("/search/label/")+14,thisUrl.indexOf("?&max"))
} else {
//thisUrl is like BLOG_URL/search/label/Blogger
const myArray = thisUrl.split("/search/label/");
postLabel=myArray[1];
}
This does work, but the page numbers calculations for the first page are for the default 20 per page. Further pages are calculated correctly per the settings number per page.
Another way is to cause the label page to load with the query string appended. This causes the page to load with only the number of posts per page as set in settings (should be set the same in the parameters set in the script), and the page numbers show the correct number of pages.
// perPage=20
window.location.href = thisUrl+"?&max-results="+perPage;
This works perfectly, but it does cause a page reload. Best would be to be able to set the label links to load with the settings number in the first place.
Comments (3)