Category Archives: Wordpress

WordPress error “Is its parent directory writable by the server?”

I was not able to upload images to my wordpress post after i transferred my entire wordpress to a new host. The error returned was
“Unable to create directory /blog/wp-content/uploads/2010/xx. Is its parent directory writable by the server?”

Tried changing the permission of the wp-content folder and its subdirectories to 775 and then to 777.

[jaguars]$ chmod -R 775 wp-content/
......
......
[jaguars]$ chmod -R 777 wp-content/

But both didnt work.. :(

Next,
The wordpress upload folder was set to /blog/wp-content/uploads in the Settings > Miscellaneous
Changed this to blog/wp-content/uploads (removed the ‘/’ before blog)
Now uploading works, but still there was a problem. The files are uploaded and saved to new folder /blog/blog/wp-content/uploads [two ‘blog‘ in the path.]

Finally, changed the upload folder to wp-content/uploads in the Settings > Miscellaneous
Everything works perfect now.

I changed back the permission setting to 755

[jaguars]$ chmod -R 755 wp-content/ 

I guess the misconfiguration happend because, in my earlier installation, wordpress was installed into root. and in here to the /blog directory.

Displaying posts in a category as a page in wordpress

In this site the Life page only displays the posts in the category Life.
I did this in a manual way by creating a Page Template for the Life page. This gives you more control. The problem with this approach is that you have to do it again for a new theme.

In wordpress, individual pages can be set to use a specific custom Page Template (a PHP template file, e.g., life.php) that we create within our Theme. The custom Page Template can be assigned while creating a new page. This new Page Template will then override the default page.php Page Template in the Theme.
When loading a page, wordpress looks first for the assigned Page template, then the page.php and finally the index.php. The first one it finds will be used to display that Page. The template pages are situated in the theme’s directory which is at wp-content/themes/your-theme

In our case we need a Page Template that will be similar to the home page but displays only the posts in the required category.
So we will base our custom Page Template on index.php which is the Page Template of the home page.

We make a copy of  the index.php with the name mypage.php (or anything.php)

Add the following code to the top of it so that wordpress understands that it is a Page Template and identify its Template Name. This name will be displayed in the theme editor page.

<?php
/*
Template Name: MyPage
*/
?>

Now, we add the filter to display only the required category. This should be added just after the above Template Name code

<?php
if (is_home()) {
query_posts($query_string."&cat=3");
}
?>

In this code we display only category with id 3. The category id can be found out from the wordpress Edit Category pages by mouse hovering the required category and its id will be shown in the browser’s status bar.
Now to display more than one category use some thing like this
query_posts($query_string."&cat=2,6,17,38");

Create a blank page and assign this custom template to it. [Look for a drop-down labeled “Page Template” towards the bottom]

Thats all!

For more detailed information on Page Templates, visit this wordpress codex page

Excluding a category from the front page in WordPress

This is a very well known trick where we use the query_posts() template tag to control which posts to show up. The code has to be placed above the Loop in the index.php template file.

<?php
if (is_home()) {
query_posts("cat=-3");
}
?>

The code checks whether we are in home page and if it is, it excludes the category with id 3 from displaying in it. The category id can be found out from the wordpres’s Edit Category pages by mouse hovering the required category and its id will be shown in the browser’s status bar.
More than one category could be excluded by using a code like this, query_posts("cat=-2,-6,-8")

However, i recently noticed that it breaks the pagination, and so the next and previous page links at the bottom only shows the same home page. Pagination is the feature by which we split the home page into pages based on the max number of posts that can be displayed in the page.

The problem was because, the call to query_posts() causes the wp_query object to generate a new SQL query using our parameters and ignores the other parameters it receives via the URL (page number etc).

The proper way is to send the parameters in the URL together with our parameters and this can be done by including the variable $query_string in the call to query_posts(). When doing this way the quoted portion of the argument must begin with an ampersand (&).
The code now looks like this

<?php
if (is_home()) {
query_posts($query_string."&cat=-3");
}
?>

Another technique is to use a code like this inside the Loop.
<?php if (in_category('3') && is_home() ) continue; ?>

I’ve not tested this code myself, but looking at it i think it should work fine.

For a detailed information on what the query_posts() is capable of doing, visit this wordpress codex page