Increasing the number of posts per page on category, tag, and archive pages in WordPress

In WordPress, you can set the number of pages to display per page in the Administration settings. This is set in Admin/Settings/Reading.

The issue with this is that this is a global setting. If you would like to set a different number of posts to display on the front page than on the category page, you can do it by adding this code to functions.php in your theme.

The following code displays 20 posts per page on all pages that are not the front page (index). This includes search results, categories, tag pages, archives, and author listings.

function change_number_of_posts($query) {
	if ( ! is_front_page()) // Make sure it is not the front page
	$query->query_vars['posts_per_page'] = 20; // Change 20 to the number of posts you would like to show
	return $query; // Return our modified query variables
}
add_filter('pre_get_posts', 'change_number_of_posts'); // Hook our custom function onto the request filter

You can change this only for category pages for example with this code.

function change_number_of_posts($query) {
	if ( $query->is_category ) // Make sure it is a category page
	$query->query_vars['posts_per_page'] = 20; // Change 20 to the number of posts you would like to show
	return $query; // Return our modified query variables
}
add_filter('pre_get_posts', 'change_number_of_posts'); // Hook our custom function onto the request filter

The result is that you can set the global setting in the WordPress admin page to 10 posts, which affects the front page (index). You can then insert this code into functions.php and all other pages will display 20 posts.

Note: You do not have to modify your theme other than functions.php for this to work.

Zero day vulnerability in many WordPress themes

Mark Maunder announced a zero day vulnerability in many WordPress themes yesterday here on his blog.

If you use any third party WordPress themes, you should check your server for the presence of timthumb.php or thumb.php. It is reported that several theme marketplace websites host common legitimate themes that utilize this library.

The fix is to remove any allowed sites from the thumb.php or timthumb.php files as recommended below.

BEFORE:

$allowedSites = array (
	'flickr.com',
	'picasa.com',
	'blogger.com',
	'wordpress.com',
	'img.youtube.com',
	'upload.wikimedia.org',
	'photobucket.com',
);

AFTER:

$allowedSites = array ();

Please read the full technical details at Mark’s blog in the link above.

WordPress XML Sitemap Plugin Review

I have been building quite a few sites with WordPress lately. WordPress has quite a long list of 3rd party plugins developed for various tasks and functions.

One downside to this is that there are several redundant WordPress plugins for common tasks, and their plugin search mechanism which is located at http://wordpress.org/extend/plugins/ is somewhat difficult to use.

I tend to search for the most installed or popular plugins and use the hive mind’s collective research to choose which plugin is the best, most robust, and best supported. Installing the most installed plugin does not always ensure that it is the best plugin, so I tend to test different WordPress plugins from time to time.

Recently, I installed Khang Minh’s XML Sitemap plugin called “Better WordPress Google XML Sitemaps (with sitemapindex and Multi-site support).” This creates a sitemapindex.xml file which references several other sub-sitemaps. This is the new trend in XML sitemaps because there is a 50,000 entry limit for a single sitemap file. By splitting the sitemaps into sub-sitemaps, you can broaden the number of items that you can index.

WordPress XML Sitemap Plugin

You can get the plugin from the WordPress plugin project page here. You can also visit Khang Minh’s website at http://betterwp.net/ which also showcases his several other WordPress plugins.

I also want to note that I had a problem with the plugin. The category sitemap wouldn’t generate. I posted a bug report to the issue queue, and he contacted me via Skype and did some testing on my WordPress installation. He found a bug with the code, fixed it, and created a new patch. The problem was with my database, there were several posts had been deleted, but were still categorized as “Uncategorized” which is the default WordPress category for new posts.

This is absolutely the best support I have ever received from a WordPress plugin or Drupal module developer. I have to say that he was a very nice guy, fixed the problem, and devoted his time to not only resolving my individual issue, but creating a patch to fix the particular scenario for the greater community as a whole.

I have not found any problems with any of the other WordPress XML sitemap plugins, but I will use the Better WordPress Google XML Sitemaps (with sitemapindex and Multi-site support) due to the high level of support that Khang Minh provides. His plugins seem solid and he has written and maintains several, so he has a high familiarity with the WordPress framework.


Other XML Sitemap Plugins of note are as follows:

How to display nicely formatted PHP code in a WordPress post

I’ve been struggling for a while about how to embed PHP, HTML, or CSS code into WordPress posts so that they look good and are easy to understand.

I found this list of 12 WordPress Plugins to Display and Highlight Code.

I researched a few of them and finally settled on SyntaxHighlighter Evolved, which was simple to install, easy to use with short codes, formats nicely, and seems to have a large existing user base.

In your posts, you can simply use [php] and [/php] shortcodes around your actual PHP code and it does it’s trick. You can review the plugin page for the many various types of languages/syntax that are available.

I will spare your eyes and use this for all embedded code from now on.

Updating Price PHP print statements in Ubercart

Recently, I updated an Ubercart shopping cart system on Drupal that was very out of date.

After the upgrade, the list price on the product pages had too many zeros. It looked like this.

MSRP $ 49.99000

After a bit of research, I learned that Ubercart has been updated to include more decimal places to accommodate more International currencies.

I took a look at the node-product.tpl.php template and found that the print statement for the list price was using the out of date print statement.

The old print statement looked like:

list_price ?>

The new print statement looks like this:

list_price); ?>

Now all is fine.

MSRP $ 49.99

Consulting

I'm currently available
for Lotus Notes / Domino consulting engagements.

LinkedIn

Connect with me:

LinkedIn

Advertisement
Advertisement
Categories