Product - Category Name Bug in WordPress
If you have ever built an ecommerce website using WordPress than you might have seen the tricky first product-category name bug. e have developed a quick dirty hack to making first product names appear properly (Wp e-Commerce). The rest of the Web6S team said I should impart my Wordpress knowledge to the massesand reveal my secrets. So here goes nothing.
The problem: When clicking on a product category and navigating to it's respective list of products, the first product in the list would display the category name rather than the name of the product. After doing some research I foud a few answers. 1. Some found that the problem was in the page.php file in your theme folder. You can read about it at the beginning of this post: http://gasolicious.com/commerce-product-category-pages/
There are different places that you will find the post title in different themes, so it may take some looking around. That post covers some of them.
2. Since I was working with the Thematic theme, I found a solution where I could alter the post title. It was in functions.php - by putting in something like this: http://getshopped.org/forums/topic/thematic-fix-product-title-displayed-instead-of-category-title/ This repair method though would take a bit of tweaking since the fix deals with the opposite problem (trying to get the category name to display instead of the product title). Needless to say, this was not the fix for me.
3. Some found the solution by calling the product title twice in either: wpsc-products_page, wpsc-list_view where the product loop starts. For example turning this line: <?php while (wpsc_have_products()) : wpsc_the_product(); ?> into this: <?php while (wpsc_have_products()) : wpsc_the_product(); wpsc_the_product_title();?> That calls wpsc_the_product_title() once, then it get's called again when you call it to display the title.
4. Another solutions for some was removing this line of code; remove_filter('the_title','wpsc_the_category_title'); from: wpsc-includes/theme.functions.php
Well, to be honest, none of these solutions worked for me. I soon found myself resorting to an ugly hack that is a comprimize, but it gets the job done. Since the first product still linked it's correct product page, I just took the permalink of that title, stripped it down to the title portion and removed the dash. Voilla! Here is the code that I put in wpsc-products_page.php, it's place right befor calling the title:
<h2 class="prodtitle entry-title"> <?php if(get_option('hide_name_link') == 1) : ?> <?php echo wpsc_the_product_title(); ?> <?php else: ?> <a class="wpsc_product_title" href="<?php echo wpsc_the_product_permalink(); ?>"> <?php // cut the url into an array of strings separated by a "/" then remove "-" $link_line = explode("/", wpsc_the_product_permalink()); $title = str_replace("terrain", "", str_replace("-", " ", $link_line[5])); echo $title; ?></a> <?php endif; ?> </h2>
Hope this helps anyone who is experience similar problems with their WP eccomerce webiste.









