Get ID of the WordPress ‘Front Page’ in Theme’s functions.php

Problem: I wanted to add some Meta Boxes to the homepage only, and have them only visible in WP-Admin when editing that page.

Solution:  Provided that a page has been selected in wp-admin > General Settings > Reading Settings > A Static Page [Front Page], then this code can be used to pull that value out as a Page ID: Continue reading “Get ID of the WordPress ‘Front Page’ in Theme’s functions.php”

Getting subcategory totals [shopp(‘subcategory’,’total’)] to work in Shopp Plugin 1.1.*

Problem: Pulling the total number of products from a subcat in Shopp doesn’t seem to work out the box. For example, this code WON’T return the total even though the correct tag shopp(‘subcategory’,’total’) is used: Continue reading “Getting subcategory totals [shopp(‘subcategory’,’total’)] to work in Shopp Plugin 1.1.*”

Capture last viewed category in product view in Shopp Plugin for WordPress

Problem: I’m using the Shopp 1.1.9 ecommerce plugin for WordPress, and my client wanted to display specific background images while showing certain products. Shopp is very complete, but one thing that is missing in the current version ‘out of the box’ is the ability to pull the ‘last viewed’ category name when viewing a product. Obviously a product can belong to more than one cat, so it can’t know which one to display… Continue reading “Capture last viewed category in product view in Shopp Plugin for WordPress”

Add ‘Related Products’ to the Product Template in the Shopp WordPress Plugin

Problem: Today I needed to add some code to a Shopp (ver 1.1.9) product.php template so that related products (that have same ‘Tag’) would show up at the bottom. The ‘Related Products‘ template tag was not behaving as I expected it to.. i.e. it was stopping the product page rendering anything at all. Continue reading “Add ‘Related Products’ to the Product Template in the Shopp WordPress Plugin”

WordPress replaces double and triple hyphens (– or —)

Problem: The other day I was trying to type two hypens (–) in a post, and when I saved/published the post, WordPress reformatted the hypens to display as an ‘en dash‘ (–).

More Info: After some searching about, and some helpful info provided in the WordPress Codex, I found out about a WP function called ‘wptexturize’ which is applied each time a post is rendered. The function – which can be found in ‘wp-includes/formatting.php’ – replaces quite a few things, like ™ to ™ etc.

Fix: You could stop this happening a number of ways i.e. editing the function to stop it doing the replace altogether, or install a plugin that does it (maybe this one, haven’t tried it!). I decided to use WordPress’s remove_filter function to stop the reformatting taking place.

To do this, open the ‘functions.php’ file within your theme. If one does not exist, create it.

Add the following code to the bottom of the file, taking care not to end up with too many or too few <?php tags:

<?php
remove_filter('the_content', 'wptexturize');
remove_filter('the_title', 'wptexturize');
?>

Then save the file (or ‘update’ if you’re doing this via the theme editor in WP admin) and view your post. That should do it! (proof is here, you can only see those double and triple hyphens in this blog post title because I’ve just added the code above to this sites functions.php also!)

Add ‘Drafts’ sorting to Shopp Products list

Problem: There is no ‘drafts’ view filter in the Shopp (>1.1.9) Product Manager, i.e you can’t quickly list all the products that have ‘draft’ status in one go.

Fix: I made this mod to answer a question in the Shopp Helpdesk forum, it’s not very tested, but seems to work perfectly!

Open ‘wp-content/plugins/shopp/core/flow/Warehouse.php’ and replace this:

198
$subfilters = array('f' => 'featured','p' => 'published','s' => 'onsale','i' => 'inventory');

With this:

198
$subfilters = array('f' => 'featured','p' => 'published','d' => 'draft','s' => 'onsale','i' => 'inventory');

Then in the same file replace this:

199
200
201
202
203
204
205
$subs = array(
'all' => array('label' => __('All','Shopp'),'columns' => "count(distinct pd.id) AS total",'where'=>'true'),
'published' => array('label' => __('Published','Shopp'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.status='publish'",'request' => 'p'),
'onsale' => array('label' => __('On Sale','Shopp'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pt.sale='on'",'request' => 's'),
'featured' => array('label' => __('Featured','Shopp'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.featured='on'",'request' => 'f'),
'inventory' => array('label' => __('Inventory','Shopp'),'total' => 0,'columns' => "count(distinct pt.id) AS total",'where'=>"pt.inventory='on' AND pt.type!='N/A'",'grouping'=>'pt.id','request' => 'i')
);

With this:

199
200
201
202
203
204
205
206
$subs = array(
'all' => array('label' => __('All','Shopp'),'columns' => "count(distinct pd.id) AS total",'where'=>'true'),
'published' => array('label' => __('Published','Shopp'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.status='publish'",'request' => 'p'),
'draft' => array('label' => __('Draft','Shopp'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.status='draft'",'request' => 'd'),
'onsale' => array('label' => __('On Sale','Shopp'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pt.sale='on'",'request' => 's'),
'featured' => array('label' => __('Featured','Shopp'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.featured='on'",'request' => 'f'),
'inventory' => array('label' => __('Inventory','Shopp'),'total' => 0,'columns' => "count(distinct pt.id) AS total",'where'=>"pt.inventory='on' AND pt.type!='N/A'",'grouping'=>'pt.id','request' => 'i')
);

Hopefully this will be included in a future version of Shopp.