WordPress as a CMS:Too Complicated for Clients?

It depends.
I’ve noticed that my clients are not big on selecting categories when they write new posts. And it is the rare client that pays any attention to Tags.But for the average client I would not recommend setting up a site that needs Custom Fields. Categories, yes. Categories are far more intuitive and a much easier concept to grasp.If your client is advanced enough to use Custom Fields chances are they don’t really need you at all!

But for the average client,if I have set up a site that depends on the correct selection of categories before publishing, I have to teach them that they must select the right category when writing a new post.If they get it (and most of my clients do get) it works.
Using WordPress as a blog does not depend on picking the right category. Because all posts get looped by index.php whether they are in category 3 or category 1003. But maintaining a site that is using WordPress as a CMS and a blog requires playing by some simple rules.

WP as a CMS, 2 Blogs in One
Here is an example of WordPress as a CMS that might be considered “too complicated” for some clients to upkeep. This site has a home page template using one version of index.php and a simple custom query to show only Featured posts. While another template loops only the Events posts. For this site I kept it very simple by creating only 2 categories. By keeping it this simple and knowing that my average client does not tend to create new categories just for kicks fingers crossed, this will be an easy site to maintain.

How to get 2 “blogs” in one. One “blog” on the frontpage that shows only one category and another “blog” that will use one master category to show all the other posts.
I left Reading settings as “Frontpage displays: your latest posts”. I wanted those latest posts to be from only one category. And then I wanted to exclude these posts from the other “blog” and vice versa. The question was use a category template or use a custom query in a template? I’ve used both and it’s my opinion that category templates are the better way to go.

Using a custom query
Trying to get posts in a template from one or 2 categories using a custom query breaks the next post navigation. This means you either have to set your Reading settings to show 100 posts or to use the showposts=100 in the custom query. It’s not that elegant. And I always felt it was a broken but working kind of way to use WP. Meaning it sort of does what you want but not really.

Using a category template
To use a category template all you have to do is copy your index.php and rename it category-1.php.
In this project’s case, category 1 is the Events category which is the second blog and is going to be used as a “real” blog. Upload category-1.php to your theme folder. That is all you have to do.How does WP know to use this file? When it comes to categories WP is set up to look for a category template first.

How to keep posts belonging to category 1 out of the front page?
Paste this in the template you are using for the Featured posts to keep category 1 posts out of the front page: [php]<?php query_posts($query_string . "&cat=3,-1"); ?>[/php]

code explanation
Category 3 is the Featured Posts category that I do want on the front page. Category 1 has a minus before it because I do not want posts from the Events (category 1) showing upon the home page.The template for the Featured posts is the main index.php file.The template for the Events Posts is a copy of the main index.php file.


How to keep posts belonging to category 3 out of the Blog?

Because WordPress will show posts from a specific category if you use a category template only posts from the Events category will show up on the blog pages. So you don’t have to do anything extra to this template.

Navigation
If Categories are the backbone of WordPress then Navigation is the backbone of your website.
(Many ready made themes already provide this in header.php ) but are set up for WordPress to be used as a blog so they probably include a link to Home and then add in the code below as well. But if you write a page called Home “Home” will then show up twice in your menu–which you probably don’t want.I find it is easier to include or exclude pages from my top navigation rather than hand coding in a link to pages. Here is how to include or exclude:
[php]<ul id="nav"><?php wp_list_pages(‘sort_column=menu_order&depth=1&exclude=12,16,18&title_li=’);?></ul>[/php]

code explanation
What this does is build a navigation menu of your pages while excluding pages with ids 12,16 and 18.
Excluding pages from the top menu is easy– all you have to know is the id number of the page you would like to exclude.This code will not show child pages.*

If you need a category title to show in your navigation you can do this:
[php]<ul id="nav"><?php wp_list_pages(‘sort_column=menu_order&depth=1&exclude=12,16,18&title_li=’);?><?php wp_list_categories(‘sort_column=name&title_li=&exclude=3’); ?></ul>[/php]

code explanation
Now your menu will show all your pages and at the end will show the Events category but will exclude the Featured category.

This does have it’s drawbacks.There is a limit to how many tabs you can have in a horizontal menu without going 2 tier. If my clients don’t add new categories doesn’t mean your client’s won’t.

So another way to insert a tab for the Events category would be to do this:
[php]<ul id="nav"><?php wp_list_pages(‘sort_column=menu_order&depth=1&exclude=12,16,18&title_li=’);?><li><a href=" <?php echo get_category_link($category_id=1);?> ">Events</a></li>
</ul>[/php]

Of course this has it’s drawbacks, too. It will make sure your menu doesn’t get overcrowded with category tabs but it will only create a tab for the Events category. If there are child categories of the Events category they will not be displayed in the list of posts. (**Not True!-Yay**)Still, this might be the best way to go. You can show other categories in a sidebar or use a query to show the child categories in the Events category template. Or you can use Yet Another Related Posts plugin (YAPP) or similar that creates a list of related posts using parameters.

Any site you hand off is going to require some attention from you.If you know you won’t be able to give your time try to set up the website accordingly. Don’t expect a client to get it right away. Be prepared to repeat instructions.

*This plugin will create a dropdown on any page with child pages:Multi Level Navigation .It should be used to replace your current menu so pay attention to the Advanced options.You will have to play with the css a bit but they also provide a css generator.

Invalid argument foreach() error in WordPress Shopping Cart Plugin

my cart iconFor the longest time I held off upgrading any of my client’s stores using WP-Shopping Cart plugin because on my test install of WP I could not get RC1 3.6.8 to work.But it really bothers me not to use the latest version of something so on one client site I did the upgrade and tested it out.I got the same exact errors I got on my test install after trying to checkout/submit and have the payment sent to PayPal.

The old invalid argument foreach() error.

Going to the forum I did not see a way to fix this probably because everyone has different causes for this error? I’m not really sure but there should be definite documentation on how to get rid of so people can have a working cart.

Error Log Messages
This error:
WordPress database error Unknown column ‘files’ in ‘field list’ for query INSERT INTO `wp_cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping`, `files` ) VALUES (’18’, ’75’,’64.50′,’0′, ‘0’,’1′, ‘0’, ‘1’, ”) made by nzshpcrt_submit_checkout

Led to this error:

PHP Warning: Invalid argument supplied for foreach() in /xxx/web10/xxxx/pow.xxxl/htdocs/site/wp-content/plugins/wp-shopping-cart/merchants/paypal_multiple.php on line 82

And this all led to the cart being empty and the logs printing the price as 0.00. If the cart can’t put the order into the wp_cart_contents table it can’t process the order. Not being able to fill in the info leads to a PHP error.

Let’s look at this message again:
WordPress database error Unknown column ‘files’ in ‘field list’ for query INSERT INTO `wp_cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping`, `files` ) VALUES (’18’, ’75’,’64.50′,’0′, ‘0’,’1′, ‘0’, ‘1’, ”) made by nzshpcrt_submit_checkout

Everyone of those fields has to be in the wp_cart_contents table in your WP database.If your cart works perfectly all the way up to trying to test if orders can be processed- chances are when you upgraded a field or 2 even were not created.This can happen to WP upgrades as well.It is not a failing of the cart plugin.The fact that some people have no problem upgrading anything speaks to this.

The wp_cart_contents table.
——————-Type——– –Collation — —-Attributes— — — —Null—- — Default
purchaseid—–bigint(20) ——– —– — -UNSIGNED— – — — -No—— ——0
prodid—— – bigint(20) —– —— — — -UNSIGNED– — — –No—— ——0

——————Type———- —–Collation——- —-Attributes— ——Null——-Default
price——-varchar(128)——–latin1_swedish_ci ————– ——–No———-0
pnp———varchar(128)——–latin1_swedish_ci ——– — —– —-No———-0
gst ———varchar(128)——–latin1_swedish_ci ——- ——— – — No———0
quantity– –int(10)———————————— -UNSIGNED— — No ———-0
donation– -varchar(1) ——— latin1_swedish_ci—- —— — —— No ———0
no_shipping – varchar(1)——–latin1_swedish_ci ——— —- — — – No ———- 0
files ——- —text—————-latin1_swedish_ci——— —— — — No ———-

I know it isn’t really a table but it will have to do.

Fixing It
First check your error logs. It’s good to check your error logs the very first sign of trouble. If you can see the same kind of errors that I printed here you are having the same problem I was: field files was not added to the wp_cart_contents table when I upgraded. How pesky.

1st, log into your control panel find Manage Mysql and when you are in the manage mysql area, click on Administer for your WordPress database.

When you are in, look in the left side panel for wp_cart_contents. Click on it.

Please check to see if a “files” line has been added after the no_shipping line in wp_cart_contents.
If not, don’t be scared. It is easy-peasy to add a field to a database table.If the field called files is already there your problem is being caused by something else.Check the table for missing fields you can use my ugly “graph” up above.There should be 9 fields.If anyone of these fields is missing from the table you are going to get the invalid argument foreach() error.

If the field for “files” was not added – no_shipping will be the last field in this table.It was for me.

Look for this option it’s usually underneath the bottom of the table (my host uses phpMyAdmin some other managers will be set up differently).

Add 1 field(s) At End of Table.

Leave the 1 field to be added. Leave the radio button for At End of Table selected.

Then look for the go button-Click go.

In the Field text box, type files and use all use lowercase.

In VARCHAR dropdown list, select TEXT.

Leave everything else alone and click the save button.It’s very important to save it or the field will not get added.

Test it Out!
You should now be able to add an item to the cart and checkout and send the payment to PayPal with no more errors and blank orders in the purchase logs,

if all your checkout and payment settings in the admin for the plugin are correct and there aren’t any other issues with the plugin besides the ones I have written about.

Monday Web Woe

Why can’t anything ever be easy? I knew changing hosts and setting up a new ecommerce website would be a challenge- especially because I had to use a new ecommerce solution that seemed to be very very beta. But I work with what I am given. The easy thing was customizing the free template to match the WordPress theme I custom made for the new site. Oh what a walk in the park compared to other stuff. I have encountered new things these past weeks: Private SSL, openssl,Dedicated IP,openbase,corporatese and sysadmins who might be drinking on the job.

Corporatese I can manage.I read 1984, I knew it was coming:the newspeak. I can imagine it comes as second nature to business school types. I went to art school and the jargon I picked up (to mock it) was just as full of hot air. In artschoolspeak the point was to sound like you were really saying something especially if you were talking about your work. In corporatese the point is not to let anyone know what you are talking about especially if you are talking about your work.

The ecommerce site launched like a tiny little dream with https all over the place. 2 days later the dream vanished and we found ourselves without a dedicated ip. Ssl certificates will not work without a dedicated ip address. It is as if we don’t have an ssl installed at all and are reduced to self signed. Browsers just love this.There is no way anyone is ever going to buy anything if they have to add an exception to do so.There is even a button on the error message that says Get me out of here! With an exclamation point and everything. Who is going to see that and say “oh, I don’t care but I want to buy the item anyway”.

Get Grid View Without the Gold Cart

gratuitous blog post imageWPSC means WordPress Shopping Cart, a plugin for WordPress.

What: Too cheap to buy a Gold Cart Module for your WPSC plugin? Well, it isn’t only out of cheapness that I’m writing this (anyway I make my clients buy the module for other reasons like more payment gateways than PayPal) it’s the constant battle to optimize SEO. This shopping cart plugin is possibly the best thing to happen to WordPress but it gives less than great SEO. Duplicate title tags,missing or too short meta descriptions.

How: Use the WordPress editor in Visual Mode to insert a product group into a Page or Post.

The more familiar I get with how low ranking websites get knocked for duplicate content (yep, Google gives more leeway to popular sites with loads of incoming links and high page rank) the more value I see in adding a product group/category to a page or post rather than use the one page to show your entire store.

The editor in HTML mode will not show the shopping cart button. And if you turned this option off in your user profile you won’t ever see this button. So go to your user profile and turn Use Visual Editor back on.
So go to Write > Page and click on the cart icon to choose a category from product groups. Select, insert,save. Once you preview you’ll see that the products scroll down the page.
Don’t publish just yet.

Here is some sweet sweet CSS to fake the Grid View, save 20 bucks and get some good SEO working (that those rich guys that paid for Grid View probably won’t have).
This part is so incredibly easy I could kiss myself. In fact I will.

Fake Grid View CSS
Add this to style.css in your theme folder:
[css]
#homepage_products{overflow:hidden;}
#homepage_products .category_view_product .product_details .wpsc_product_title{font-size:12px;}
#homepage_products .category_view_product{width:200px;height:300px;float:left;margin:8px 3px;}
[/css]
The height and width and margins will have to be tweaked to fit your wishes.You can make the product titles smaller and change color.You can also have borders.It’s wide open for customization.But the float:left is what matters and creates the grid.Having overflow:hidden in the wrapper div keeps the page from looking screwy.

SEO
Next thing is to download the All in One SEO pack plugin for WordPress, unzip, upload to plugins folder, activate settle up the options and go back to your almost done Page or Post.Pop open the All in One SEO box in the editor page, below Categories. You’ll see title,description and keyword fields. Writing in your description will solve the short or missing meta description problem. If you used a post you can skip the keywords field and use tags instead. Tags are better anyway.

Use a Page or a Post?
In WordPress categories are king and you can great things with category templates.You can only use categories with posts. I would rather be able to place a single product into a Post.I think this would open up a lot more flexibility in using this plugin. This is supposed to be an option in the latest release of the plugin but either it doesn’t work or I have another plugin that breaks the button code for this. Entirely possible.

Last but not least tweak your header.php. Look for the line with html]blah blah blah [/html] delete it and paste this in it’s place:
[php]<title><?php

// Page or Single Post
if ( is_page() or is_single() ) {
the_title();

// Category Archive
} elseif ( is_category() ) {
printf( __(‘Archive for &lsquo;%s&rsquo;’), single_cat_title(”, false) );

// Tag Archive
} elseif ( function_exists(‘is_tag’) and function_exists(‘single_tag_title’) and is_tag() ) {
printf( __(‘Tag Archive for &lsquo;%s&rsquo;’), single_tag_title(”, false) );

// General Archive
} elseif ( is_archive() ) {
printf( __(‘%s Archive’), wp_title(”, false) );

// Search Results
} elseif ( is_search() ) {
printf( __(‘Search Results for &lsquo;%s&rsquo;’), get_query_var(‘s’) );
}

// Insert separator for the titles above
if ( !is_home() and !is_404() ) {
_e(‘ at ‘);
}

// Finally the blog name
bloginfo(‘name’);

?></title>[/php]

That helps take care of the duplicate title problem for categories and archives.
The all in one seo pack does most of the work and this does the rest. It’s very cool.