Sunday, October 26, 2008

Useful tips to turn your Wordpress into a CMS - 3

WP Pluggin - List Category Posts


List Category Posts allows you to list posts from a category into a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, and the number of posts to display. You can use [catlist] as many times as needed with different arguments


My requirement was this.My site has a knowledge base for which a lot of articles are created as posts. All these posts come under the category "articles". I downloaded the plugin, copied it into the wp-content/plugins directory and activated it form admin panel. Then I created a page with title "Articles" (no need to be the same as the category, it was my choice) where I wanted to list all the posts under this category. So I just added this line to the page content:



[catlist name="articles" numberposts=-1 orderby=title]
name - category name
numberposts - number of posts to be displayed per page
orderby - sorting order

This worked fine for me as all my posts were within the "article" category, but as soon as I created some posts in another category called "faq" and created a sperate page with shortcode [catlist name="faq" numberposts=-1 orderby=title] it listed all my post that come under both articles and faq. So I checked back the articles page and now it is also listing all the posts form all categories. So I decided to check the plugin code for the file wp-content/plugins/list-category-posts/list_cat_posts.php. I found out an if condition with a wrong test in list_category_posts() function:

if($atts['name']!='default' && $atts['id']!='0') which will never be satisfied as we are giving either category name or category id but not both. So I just changed the "&&" joiner to "||" and everything started working fine. I am going to notify the author of the plugin. But apart from this issue, it is a very nice one. Thanks to him.

You can see this in action here or here

Monday, October 20, 2008

Useful tips to turn your Wordpress into a CMS - 2

WP Plugin - Dagon Design Sitemap Generator



If you want to create a sitemap for your site which will automatically update whenever you add a new post or page, this plugin is a good candidate.

This plugin creates a sitemap for your WordPress powered site. This is not just another XML sitemap plugin, but rather a true sitemap generator which is highly customizable from its own options page in the WordPress admin panel. Some of its features include: support for multi-level categories and pages, category/page exclusion, multiple-page generation with navigation, permalink support, choose what to display, what order to list items in, show comment counts and/or post dates, and much more.

So., I created a top level page, in the content editor chose the HTML editor and added a single line.
<!-- ddsitemapgen -->
This will give you a basic site map. To further tune this go to:
Settings->DDSitemapGen

My settings are:

Items per page: 50

Sitemap page slug: sitemap (if you are using permalinks)

What to show: Pages and posts (You can chose to show either your pages or posts or both)

If showing both, which first: Pages first (Pages is defining my site layout)

Page sort order: By menu order (ascending) - ( This will give the structure of pages and sub pages.)

Excluded categories: 1 (Excluding "Uncategorized" category)

Other setting of interest are: Sitemap navigation method,Show sitemap navigation etc...

See this in action here

Thursday, October 16, 2008

Useful tips to turn your Wordpress into a CMS -1

Worpress is a wonderful blogging tool which i have using for last two years. When I planned to create a new website recently, my first consideration was a good CMS and I chose joomla as the one. Joomla is one of the best open source CMS's in the world and I did design a moderate(not bad at least) web site. But still I didn't feel the comfort that I had when I was using wordpress - nothing technical, just my inertia to changes. At last I decided to go back to wordpress and tweak it for my needs. With some basic tweaking and many plugins, I made a website easily. I will post them here for anybody want to make use of this.

Disabling comments and pings

One of the primary requirement when converting a blog software to cms is to disable comments and pings (this depends on how you want your site to be) . To do this we will alter the WP database a little.

If you have already created lot of pages, you will have to first disable them. This is what I did for my site.

mysql> update wp_posts set ping_status='closed',comment_status='closed' where post_type in ('post','page');
Query OK, 36 rows affected (0.00 sec)
Rows matched: 55 Changed: 36 Warnings: 0

Now we should set the default value for these settings to closed.

mysql> alter table wp_posts alter column ping_status set default 'closed';
Query OK, 0 rows affected (0.21 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table wp_posts alter column comment_status set default 'closed';
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0

This alone will not help to disable comments/pings because the editor to create page/post by default will have the options to allow comments/pings as enabled. To change it

Go to: Settings -> Discussion -> Default article settings and clear all settings

You are all set. Comments will be disable in your web site now.

Friday, October 3, 2008

Flushing linux memory cache

I was looking for a fix to free the unused RAM in Linux. After searching for sometime and doing some research, I found this solution.

root@enjoyfast-lx:~# free -m
total used free shared buffers cached
Mem: 1002 984 18 0 89 386
-/+ buffers/cache: 508 494
Swap: 2047 0 2047
root@enjoyfast-lx:~# sync
root@enjoyfast-lx:~# echo 3 > /proc/sys/vm/drop_caches
root@enjoyfast-lx:~# free -m
total used free shared buffers cached
Mem: 1002 600 402 0 0 112
-/+ buffers/cache: 487 515
Swap: 2047 0 2047

root@enjoyfast-lx:~# echo 0 > /proc/sys/vm/drop_caches

The sync command will write the contents of cache into hard disk. But the cached pages will still remain in memory for quick access. This will actually speed up the execution of programs that are currently accessing this pages. But if you are running out of memory and need to free up some RAM, you can remove this pages from cache permanently bye changing the value of /proc/sys/vm/drop_caches to 3 . Now a quick analysis of what happens when we do this can be done by using the /proc/meminfo file.

Before running the above fix:

root@enjoyfast-lx:~/temp# cat /proc/meminfo > mem.b4

After running the fix

root@enjoyfast-lx:~/temp# cat /proc/meminfo > mem.af8r

root@enjoyfast-lx:~/temp# diff -y mem.b4 mem.af8r|tr -d '|'|awk '{ print $2"\t"$5"\t"expr $5 - $2"\t"$1 }'|awk '{if($3 != 0)print $0}'|sort -k4
474136 395276 -78860 Active:
346992 347096 104 AnonPages:
96172 452 -95720 Buffers:
396076 115380 -280696 Cached:
953836 954052 216 Committed_AS:
316 80 -236 Dirty:
1608 69064 67456 HighFree:
365060 67608 -297452 Inactive:
13992 342888 328896 LowFree:
15600 411952 396352 MemFree:
2928 2932 4 PageTables:
35480 15528 -19952 Slab:
25088 6308 -18780 SReclaimable:
10392 9220 -1172 SUnreclaim:

As you can see, its freeing up buffers and cache. For a complete reference of this values, go to:

http://www.redhat.com/advice/tips/meminfo.html