Click here for HomePagewww.RadMod.com
St. Louis, MO USA
The Radical Moderate
Covering: Big Brother, Propaganda, Theocracy and Liberty
By Tim Willoughby, Y.A.W.L. *
(* Yet Another Wretched Lawyer)
Search Disabled Temporarily
 
HOME RM's Platform RM's Quals About the RadMod TimsLaw.com
 

Libertarian Democrat

A Libertarian Democrat is vigorously pro-personal liberty, and believes government can play a constructive role in regulating our economy and providing a social safety net.

Categories:

About

Help Beta Test:

  • The RadMod is trying to convert an old fashioned HTML business website, TimsLaw.com, over to Wordpress. Feedback on how TimsLaw works would be appreciated.

Credits:

Internal Links:

A Moderate Motto:

"Few things in life are as good or as bad as they seem in the emotions of the moment."
--- An Anonymous Moderate

Wordpress “Posts Per Page” variable is EVIL !!! [updated]
Posted in Category: WordPress

Yes, Posts Per Page (PPP) is EVIL !!! Everything that displays whole posts or lists of titles keys off of the same PPP, and that causes all sorts of problems in getting Wordpress to cooperate

Quick test: Does Wordpress have separate settings for each of the following major functions?

  • Number of Posts to appear on front page automatically
  • Number of Post Titles to be listed when viewing a Category
  • Number of Post Titles to be listed in Search Results

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

But what about those of us who like only ONE post, our most recent article perhaps, on our front page?

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

I recently decided to abandon DC nicer archives on Radmod.com due to DC resetting “posts per page” to 9,999 and breaking my admin interface, crashing my firefox browser, and creating mayhem with the database, as it chokes trying to display every single article.

Once again, see my Wordpress as a Content Management System article for more details.

After abandoning DC nicer archives, and restoring a typical Wordpress loop to display my category posts, I reset PPP to 10 —- Oops, mistake.

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.

Well, I tweaked my Wordpress Loop to display only the first post in the Post Array, rather than let the Loop go through the entire array and display all 10 posts (or whatever the PPP setting is).

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.

Be assured that there are MANY different ways to accomplish the goal of displaying ONLY the single most recent article on the front page. Here are a few:

  • Use the plugin “Customizable Post Listing” and set it to get only ONE article, and get that article in full
  • Construct a WP-QUERY (I don’t know enough to do this without 15 trials and errors)
  • Use one of the Wordpress GET_ARCHIVES template functions (but then I have to go through 15 trials and errors before I get the code right
  • Figure out how to insert a “BREAK” - type of command into the Wordpress WHILE function, breaking the Loop after the first post —- I tried this three times, trying to insert an “ENDWHILE” command, and couldn’t get it right, and crashed the website each time. I just don’t know enough PHP to do this stuff right.
  • OR, Remove the WHILE command from the Loop, leaving only a single post to be processed. [UPDATE — I tried that and it worked fine, but didn’t allow me to exclude some categories of posts, so I continued to work on solutions ……
  • SOLUTION (the latest one anyway) —– A complex (for me) IF test —– see below

SOLUTION: Putting only a Single Post on the front page, excluding posts from certain categories

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 —–

Try this code in your index file, directly below the first line of LOOP code

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:

  • If we are on the homepage … [Wordpress knows if the user wants the site-root (homepage) or wants a specific article. If we’re on a specific article page, don’t do anything, just display the article as normal] ….
  • … Since we’re on the Homepage, now see if the First Post’s category is 16 or 15 …
  • …….. If we’re on the homepage, AND the category is 15 or 16, then invoke the ‘continue’ command, which skips the rest of the Loopcode and returns to the top of the Loop and works on the next post … [by “continuing” we skip the display of that post]

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

SOLUTION to the evil that is “Posts Per Page”

Wordpress needs to have a few new Admin settings:

  • Number of Posts to appear on front page automatically
  • Number of Post Titles to be listed when viewing a Category
  • Number of Post Titles to be listed in Search Results

Here is a straight “copy and paste” of the section on POSTS PER PAGE from my article on “Wordpress as a Content Management System”

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.

Big problems ensued with both DC-Nicer-Archives AND SEM-Search-Reloaded, due to their “posts_per_page” method of determining how many articles to list on a page.

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.

Does the “posts_per_page” setting affect anything other than the number of posts automatically displayed on the front page?

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.

I STOPPED using DC-Nicer Archives as of March 22, 2006 on RadMod.com. DC Nicer Archives resets “post per page” to 9,999 - breaking my admin interface unless tweaked

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.

I tried tweaking SEM Search Reloaded

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.

 

END of article
    (Printable version)    

 

3 Responses to “Wordpress “Posts Per Page” variable is EVIL !!! [updated]”

  1. Viitoria Says:

    Try the plugin “Custom Query Strings,” just google it. It will let you set different number of posts for every page.

  2. Tim the RM Says:

    Thanks for the hot tip. I will consider testing the CQS plugin when I do my next code update. That’ll give the plugin more time to mature.

    Here’s the link to Matt Read’s Custom Query Strings plugin.

    http://mattread.com/projects/wp-plugins/custom-query-string-plugin/

  3. Martijn Says:

    The solution is easy. Use query _ posts(’showposts=x’) replacing x with the number of posts you want to show. Then use is _ home , is _ search and is _ category to see where you are and set the correct value.

Leave a Reply

You must be logged in to post a comment.



Link:
Wordpress “Posts Per Page” variable is EVIL !!! [updated]

by on Wednesday March 22, 2006.
Category: WordPress.

 

PREVIOUS post in SAME category as this post:
New theme

 

NEXT post in SAME category as this post:
WP-Print 2.03 problem - fixed by reverting to old version

The RM is a "Libertarian Democrat"

A Libertarian Democrat is vigorously pro-personal liberty, and believes government can play a constructive role in regulating our economy and providing a social safety net.

Lawyers Must
Speak Out!

We must keep our ears tuned to the degeneration toward tyranny.
See Justice O'Connor's Warning.

Recent Rants:

  1. Ron Paul and Rick Santorum are nutjobs
    in Cat: Politics-misc, Theocracy, Privacy, Big Brother & Police State
  2. We are so often idiots and zealots these days
    in Cat: Politics-misc, Theocracy, Privacy, Propaganda-Media, Big Brother & Police State
  3. Interpetting that Roger Ailes joke about Obama, Bush and Terrorism
    in Cat: Propaganda-Media
  4. Example of Dem wingnuttery in an extreme gun ban bill (it’s probably DOA tho)
    in Cat: Politics-misc, Libertarian
  5. 11th Circuit says no right to sexual privacy, upholds Alabama ban on sale of dildos
    in Cat: Theocracy, Libertarian, Law-Courts
  6. The era of Republicans ignoring the Golden Rule has ended
    in Cat: Politics-misc
  7. National Park Service no longer discusses age of Grand Canyon - Bush further muzzles science
    in Cat: Science vs Religion
  8. Disease of willful ignorance
    in Cat: Politics-misc
  9. St. Louis County touchscreen voting: Great news and awful news
    in Cat: Politics-misc
  10. GOP merges terror and culture wars: Porn prosecutions UP, Crime -Terror prosecutions DOWN
    in Cat: Libertarian, War

Links:

Politics
Anti-Theocracy
Media Watchdogs
  • MediaMatters.org
    Former right wing propagandist saw the light, and shines light on right wing media
  • NewsBusters
    Focusing on liberal bias in the media, food for thought for moderates and liberals
  • Newshounds
    The NewsHounds keep a close eye on the FoxNews propaganda machine
Misc
HOME  | Top of page  | Tim's Employment Law site - www.TimsLaw.com

CONTACT the RadMod

[powered by WordPress.]

Get Firefox!