<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sitecoders.net</title>
	<atom:link href="http://www.sitecoders.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitecoders.net</link>
	<description>Web applications development for charitable and campaigning organisations</description>
	<lastBuildDate>Sun, 01 Apr 2012 15:55:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Displaying Multiple Images in WP E-Commerce</title>
		<link>http://www.sitecoders.net/2012/01/displaying-multiple-images-in-wp-e-commerce/</link>
		<comments>http://www.sitecoders.net/2012/01/displaying-multiple-images-in-wp-e-commerce/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 15:08:51 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.sitecoders.net/?p=61</guid>
		<description><![CDATA[I needed a way of displaying multiple images in a WP e-commerce installation. In order to do this I hacked the wpsc-single_product.php file that was being used in my theme (the one copied across to the theme folder) I replaced the following code form line 32 onwards 32 33 34 35 36 37 38 &#60;a [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a way of displaying multiple images in a WP e-commerce installation. In order to do this I hacked the wpsc-single_product.php file that was being used in my theme (the one copied across to the theme folder)</p>
<p>I replaced the following code form line 32 onwards</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;a rel=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_image_link_classes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
	&lt;img class=&quot;product_image&quot; id=&quot;product_image_<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_thumbnail<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product_image_width'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product_image_height'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'single'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
&lt;/a&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'gold_shpcrt_display_gallery'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">echo</span> gold_shpcrt_display_gallery<span style="color: #009900;">&#40;</span> wpsc_the_product_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">sb_get_images_for_product<span style="color: #009900;">&#40;</span>wpsc_the_product_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//...then display all of the images</span></pre></div></div>

<p>sb_get_images_for_product($id) is a function that I wrote into the themes functions.php file as follows</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">function sb_get_images_for_product($id){
	global $wpdb;
	$attachments = $wpdb-&gt;get_results($wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;posts WHERE post_parent = $id AND post_type = 'attachment' ORDER BY menu_order ASC&quot;));
	$count=0;
	foreach ($attachments as $attachment){
		$count++;
		if ($count==1){//set up first image
			echo &quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&quot;;
			$image_attributes = wp_get_attachment_image_src($attachment-&gt;ID,'thumbnail');?&gt;
			&lt;a rel=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_image_link_classes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
				&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$image_attributes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
			&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$image_attributes</span> <span style="color: #339933;">=</span> wp_get_attachment_image_src<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;a rel=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_image_link_classes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
				&lt;img class=&quot;resize&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$image_attributes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wpsc_the_product_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
			&lt;/a&gt;		
			<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>to tidy up the images I also added a little bit of css to the single_product.php as follows</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;style<span style="color: #00AA00;">&gt;</span>
<span style="color: #6666ff;">.resize</span> <span style="color: #00AA00;">&#123;</span>  
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">35px</span><span style="color: #00AA00;">;</span>  
  <span style="color: #000000; font-weight: bold;">height</span> <span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>  
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #6666ff;">.resize</span> <span style="color: #00AA00;">&#123;</span>  
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>  
  <span style="color: #000000; font-weight: bold;">height</span> <span style="color: #00AA00;">:</span> <span style="color: #933;">35px</span><span style="color: #00AA00;">;</span>  
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#TB_additional_images</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></div>

</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.sitecoders.net/2012/01/displaying-multiple-images-in-wp-e-commerce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nested categories in WordPress not playing ball</title>
		<link>http://www.sitecoders.net/2012/01/nested-categories-in-wordpress-not-playing-ball/</link>
		<comments>http://www.sitecoders.net/2012/01/nested-categories-in-wordpress-not-playing-ball/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 00:00:12 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.sitecoders.net/?p=46</guid>
		<description><![CDATA[UPDATE** AH! Typically, as soon as I find a hack for a problem I find someone has fixed it far more satisfactorily http://wordpress.org/extend/plugins/category-checklist-tree/ This has been frustrating for a while, but particularly when the same problem reared up in WP e-commerce. Effectively, when you create a new post (or in the case of WP e-commerce, [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>UPDATE** AH! Typically, as soon as I find a hack for a problem I find someone has fixed it far more satisfactorily http://wordpress.org/extend/plugins/category-checklist-tree/</p></blockquote>
<p>This has been frustrating for a while, but particularly when the same problem reared up in WP e-commerce.</p>
<p>Effectively, when you create a new post (or in the case of WP e-commerce, a new product) I expect the category tree in which I select the appropriate category to look like I created it to look, properly nested according to the tree hierarchy I have created. But it doesn&#8217;t&#8230; as soon as you start to use categories, WordPress presumes you are more likely to want to use the same categories in future and filters them out and places them at the top of the list&#8230;</p>
<p>The only thing I have found to cure this is a core wordpress hack&#8230; never my favourite solution but so far the only one I have discovered (I have some ideas for a plugin, but they haven&#8217;t come to fruition yet)</p>
<p>The problem occurs in wp-admin/includes/template.php within the function wp_category_checklist</p>
<p><code><br />
function wp_terms_checklist($post_id = 0, $args = array()) {<br />
$defaults = array(<br />
'descendants_and_self' =&gt; 0,<br />
'selected_cats' =&gt; false,<br />
'popular_cats' =&gt; false,<br />
'walker' =&gt; null,<br />
'taxonomy' =&gt; 'category',<br />
'checked_ontop' =&gt; true<br />
);<br />
extract( wp_parse_args($args, $defaults), EXTR_SKIP );</code></p>
<p>if ( empty($walker) || !is_a($walker, &#8216;Walker&#8217;) )<br />
$walker = new Walker_Category_Checklist;</p>
<p>$descendants_and_self = (int) $descendants_and_self;</p>
<p>$args = array(&#8216;taxonomy&#8217; =&gt; $taxonomy);</p>
<p>$tax = get_taxonomy($taxonomy);<br />
$args['disabled'] = !current_user_can($tax-&gt;cap-&gt;assign_terms);</p>
<p>if ( is_array( $selected_cats ) )<br />
$args['selected_cats'] = $selected_cats;<br />
elseif ( $post_id )<br />
$args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array(&#8216;fields&#8217; =&gt; &#8216;ids&#8217;)));<br />
else<br />
$args['selected_cats'] = array();</p>
<p>if ( is_array( $popular_cats ) )<br />
$args['popular_cats'] = $popular_cats;<br />
else<br />
$args['popular_cats'] = get_terms( $taxonomy, array( &#8216;fields&#8217; =&gt; &#8216;ids&#8217;, &#8216;orderby&#8217; =&gt; &#8216;count&#8217;, &#8216;order&#8217; =&gt; &#8216;DESC&#8217;, &#8216;number&#8217; =&gt; 10, &#8216;hierarchical&#8217; =&gt; false ) );</p>
<p>if ( $descendants_and_self ) {<br />
$categories = (array) get_terms($taxonomy, array( &#8216;child_of&#8217; =&gt; $descendants_and_self, &#8216;hierarchical&#8217; =&gt; 0, &#8216;hide_empty&#8217; =&gt; 0 ) );<br />
$self = get_term( $descendants_and_self, $taxonomy );<br />
array_unshift( $categories, $self );<br />
} else {<br />
$categories = (array) get_terms($taxonomy, array(&#8216;get&#8217; =&gt; &#8216;all&#8217;));<br />
}</p>
<p>if ( $checked_ontop ) {<br />
// Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)<br />
$checked_categories = array();<br />
$keys = array_keys( $categories );</p>
<p>foreach( $keys as $k ) {<br />
if ( in_array( $categories[$k]-&gt;term_id, $args['selected_cats'] ) ) {<br />
$checked_categories[] = $categories[$k];<br />
unset( $categories[$k] );<br />
}<br />
}</p>
<p>// Put checked cats on top<br />
echo call_user_func_array(array(&amp;$walker, &#8216;walk&#8217;), array($checked_categories, 0, $args));<br />
}<br />
// Then the rest of them<br />
echo call_user_func_array(array(&amp;$walker, &#8216;walk&#8217;), array($categories, 0, $args));<br />
}<br />
</code></p>
<p>The trick is to set $checked_ontop to false as follows</p>
<p><code><br />
$checked_ontop=false;<br />
if ( $checked_ontop ) {<br />
// Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)<br />
$checked_categories = array();<br />
$keys = array_keys( $categories );</code></p>
<p>foreach( $keys as $k ) {<br />
if ( in_array( $categories[$k]-&gt;term_id, $args['selected_cats'] ) ) {<br />
$checked_categories[] = $categories[$k];<br />
unset( $categories[$k] );<br />
}<br />
}</p>
<p>&nbsp;</p>
<p>I suspect there must be a way of setting the value of $checked_ontop to false without hacking core files but I haven't found it yet</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sitecoders.net/2012/01/nested-categories-in-wordpress-not-playing-ball/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

