- The Radical Moderate - http://www.radmod.com -
Wordpress “Posts Per Page” variable is EVIL !!! [updated]
Category = WordPress
Quick test: Does Wordpress have separate settings for each of the following major functions?
ANSWER: Of course not. But you expected that answer, didn’t you?
Yes, Wordpress drives ALL of those independent major functions from ONE SINGLE SETTING, the all-purpose evil “Posts Per Page” setting.
The “Posts per page” (PPP) setting is located in the Admin Screens under “options, reading”. Plugins can reset PPP as well, for their own purposes, and Wordpress 2.01 will in error retain the setting that the plugin specified, (DC nicer archives does that, breaking my admin interface).
If you are like most people, you might let Posts per page be set at 10, to automatically show the latest 10 short blog entries on the front page. You might even set PPP at 20 or more, if your entries are short.
Read on, for my adventures in solving my Posts Per Page problem. A commenter posted June 25, 2006 that Matt Read had written the Custom Query String plugin (CQS), in an attempt to deal with the PPP issue. It’ll be a while before I test the CQS plugin. As a philosophy, I prefer not to use plugins whenever possible, in order to stay as close to the Core of Wordpress as I can (minimizes conflicts).
[We are NOT talking about “creating a static front page” - we’re talking about having only the latest post appear in full as our front page article]
You might say “Well, dummy, set PPP to 1 “.
AHHH I see, is it really THAT easy? Hell NO! If I set PPP to 1, then I DO get my single post on the front page (I get the latest post, which is what I want). But guess what ELSE happens? I get only 1 search result, and only 1 article listed in the Category lists. OUCH.
I’ve raised some fuss about Posts per page before —- See my Wordpress as a Content Management System article for more details about the vile and corrupting interplay between “posts per page” and DC nicer archives, and your Search Results, and any other listing.
Once again, see my Wordpress as a Content Management System article for more details.
Guess how many articles I then got on my Front Page? Right —- 10 !
Some of my articles are quite long. I DON’T want my users waiting for 10 full articles to load on each view of the Front Page. I want ONE article per page.
So, what to do?
I DON’T want a static homepage on my political blog. I want an ever changing front page, always showing the latest post.
The number of posts in the “Wordpress Loop Array” equals the setting of Posts Per Page, and the Loop will process each article in the array by default.
I needed a way to “BREAK” the loop after the first article, or I needed a way to code my homepage so that ONLY the most recent article would be displayed.
This is an alternative to the static homepage. For a static homepage, the Wordpress Codex gives several techinques. But if you want your most recent stuff to automatically appear, except for posts in certain categories, then I’ve found a way to do that.
For example, I wanted my Wordpress political blog at Radmod.com to show only 1 article on the frontpage, the very latest. BUT, I did not want the featured article to be my latest “Wordpress”-related rambling, or my latest silliness categorized under “diversions”. I wanted it to be a political article, in line with the blog subject matter. Code follows —–
The Wordpress LOOP is the codeblock that starts as follows: [close up all spaces to use]
< ? php if ( have _ posts ( ) ) { while ( have _ posts ( ) ) { the _ post ( ); ? >
Right below the start of the Loop code, I inserted the following: [close up all spaces to use]
< ? php if ( is _ home ( ) ): ? > < ? php if ( in _ category (16) or in_ category (15) ): ? > < ? php continue; ? >< ? php endif; ? > < ? php endif; ? >
Here’s how my code works:
And my code will test each of the latest posts, until one of the posts is NOT in category 15 or 16. The first post in some truly political category will be displayerd, having skipped all the Wordpress or Diversion category posts.
Once the Loop processes a post, I have a BREAK command at the bottom of the Loop, to prevent the Loop from getting a second post. [close up the extra spaces] —
I put “< ? php break ; ? >” at the bottom of the Loop just above the following:
? php } } else { // end if any posts
My Category and Search template pages still retain typical complete Wordpress Loops. And they display the number of posts I set in the admin interface, for Posts Per Page (10 is my pref for the listings of titles and excerpts).
Wordpress needs to have a few new Admin settings:
A business website is required to have a good useful means of displaying its content, organized into categories. The default untweaked Wordpress “display category” - type of features are not acceptable.
Moreover, the built-in Wordpress search function is too weak.
So I needed an archive display program, and I needed a good search program.
I initially chose DC-Nicer-Archives as a means of displaying lists of content, whether the lists were produced through a search, or through the user clicking a Category. [But I have now disabled DC Nicer Archives on MissouriJobLaw.com]
I chose SEM-Search-Reloaded to find more relevant articles for my searchers.
The Wordpress database, in the Posts Table, has a data field called “posts_per_page“.
The Admin interface allows you to manually set posts_per_page to whatever you want. The default is 10, I think.
You bet your sweet ass that posts_per_page affects more than just setting the number of articles that appear automatically on the front page. It controls how many POST TITLES will get listed by the Search, Category, and Archive features.
Wordpress, and ALSO the popular plugins, rely on “posts_per_page” to tell them how many titles to put in a list of post titles. So, if you’ve set your Wordpress to show 3 posts per page, then your Homepage will show the latest three posts. But so will your SEARCH and CATEGORY features - they’ll be limited to 3 post titles at a time (at least that’s how MY Wordpress works).
That doesn’t make any sense to me!
Why would I want Search Results limited to 3, just because I only want three whole articles to appear on my frontpage at one time? Let’s say I have 20 articles under a Category. When a user cllicks a Category, don’t I want ALL 20 TITLES to be listed? YES! But only 3 titles will be listed if my “posts_per_page” is set to 3.
Plugins seem to be inclined to OVERLY-RELY on posts_per_page in deciding how many things to display on the page. For two examples, check out the DC-Nicer-Archives plugin’s function code file. Check out the SEM-Search-Reloaded plugin’s function code file.
DC-Nicer-Archives is the WORST offender. DC-Nicer-Archives actually RESETS a posts_per_page variable to 9,999. I found that when this variable was reset to 9,999, it broke my Wordpress admin interface, because the post management Admin interface tried to list 9,999 articles.
Before I deleted DC, I tried manually tweaking the DC-Nicer-Archives core functions on RadMod.com to have it reset the posts_per_page to only 100. That’s a kludge, but DC stopped breaking my Wordpress Admin interface. But the Admin interface then showed 100 posts, rather than the default hard-coded 15 posts.
SEM-Search-Reloaded also relies on the global Wordpress post_per_page setting. SEM Search uses posts_per_page to determine the number of search results to return for displaying.
So I tried manually tweaking the SEM Search code file to hard code “10″ into SEM-Search’s internal variable where it stores the number of posts_per_page. With the tweak, I could set my post_per_page at 1 if I I wanted, and still get 10 search results. So, although I get much better search relevancy with SEM-Search-Reloaded, my users would be limited to finding 10 articles at a time. I could increase the number easily, by editing the SEM Search plugin php file, but SEM-Search defaults to also producing excerpts of the articles it finds, and so the Search Results page gets long, even limiting the posts to 10.
Later on, when I started setting a larger “posts_per_page” setting in the Admin screens, I removed the SEM Search tweak and restored the original SEM Search Reloaded plugin. So, I once again allowed SEM Search to be controlled by the Global “posts per page” variable.
But still, SEM-Search fails to “page” the output. And so my users only get the TOP 10 search results (or whatever I set as “posts per page” results in the Admin screens).
SOLUTION to the posts_per_page problem: Wordpress needs to declare a few global variables (or classes or data fields in the database) to store the number of “SEARCH RESULTS” or “CATEGORIZED ARTICLES” to display. May I suggest: “search_results_to display” and “archive_results_to_display”. Also, the Wordpress Admin interface needs to give the user a means of setting these variables.
It makes no sense that the number of mere titles to be displayed in a Search at one time would be controlled by the number of whole articles to be displayed at one time on the Front Page of the site.
Article printed from The Radical Moderate: http://www.radmod.com
Click here to print.