Exclude a product category with WordPress E-Commerce Plugin

// The categories we want to exclude.
$exclude_categories = array(5, 10, 2);
while (wpsc_have_products()) :  wpsc_the_product();
  $category = get_the_product_category( wpsc_the_product_id() );
  if ( !in_array( $category[0]->term_id, $exclude_categories ) ) :
    // Here you display...
  endif;
endwhile;

And yeah, if you want to exclude a top level category, try something like this :

function get_term_top_parent_id( $term_id, $taxonomy ) {
  $parent = get_term_by( 'id', $term_id, $taxonomy );
  while ( $parent->parent != 0 ) {
    $parent = get_term_by( 'id', $term_id, $taxonomy );
  }
  return $parent->term_id;
}

// ...

$exclude_categories = array(5, 10, 2);
while (wpsc_have_products()) :  wpsc_the_product();
  $category = get_the_product_category( wpsc_the_product_id() );
  if ( !in_array( get_term_top_parent_id( $category[0]->term_id, 'wpsc_product_category' ), $exclude_categories ) ) :
    // Here you display...
  endif;
endwhile;

Vous pouvez en choisir deux

Fast, cheap or great

Je suis tombé sur sur ce diagramme réalisée par Colin Harman, et cela m’a rappelé la pyramide que mon boss de l’époque présentait quelquefois aux clients.

Celui-ci est titré pour du design, mais je l’ai vu s’appliquer à de divers projets de communication. L’idée, c’est qu’on ne peut pas raisonnablement vendre pour des cacahuètes (cheap) quelque chose de génial (great) dans un délai serré (fast)… Je vous laisse méditer là-dessus.

Responsive Adsense Plugin for WordPress

Responsive Adsense Plugin

I recently posted about a way to display different sizes of adverts depending on the window size. I’m sure it could be useful for a lot of people, so… I made it a WordPress plugin.

It’s a simple widget that works with your Google Adsense “Publisher ID” and some of your Advert Units IDs.

It will display on your pages the bigger unit that can fit in the widget container.

Enjoy folks !

Make your Google Adsense blocs fit your responsive design !

This is actually quite simple. The thing is to set the ad parameters depending on the window’s size before we call the show_ads.js script.

google_ad_client = "ca-pub-XXXXXXXXXXXXXXXX";
if ( window.innerWidth>979 || window.innerWidth<768 ) {
  // If the window is larger than 979px or smaller than 768px, we set the first bloc
  google_ad_slot = "XXXXXXXXXX";
  google_ad_width = 300;
  google_ad_height = 250;
} else {
  // Otherwise, we set the second one.
  google_ad_slot = "XXXXXXXXXX";
  google_ad_width = 200;
  google_ad_height = 200;
}

Travel Routes WordPress Plugin

Easily add geographical tags on a map when you write a post, and it will automatically create new countries and localities terms. You can also order those locations randomly or by date to define your routes.

Use the map as a widget, and pick your own colors to customize it.

It is a SVG map that react to users actions (mouse over posts and terms links, click on route line…).

https://wordpress.org/plugins/travel-routes/

Enjoy folks.

Add a custom class to every WordPress Widgets

function myclass_dynamic_sidebar_params( $params ) {
	$myclass = 'myclass';
	$params[0]['before_widget'] = preg_replace( '/class="/', 'class="' . $myclass . ' ', $params[0]['before_widget'], 1 );
	return $params;
}
add_filter( 'dynamic_sidebar_params', 'myclass_dynamic_sidebar_params' );

Convert SVG relative path data to absolute polyline points with JavaScript

This function return an array of the different absolute paths received as a string, converted to absolute points.

function pathToPoints( path ) {
  var paths = path.split( /z|Z/ ), points = new Array();
  for ( var i = 0; i < paths.length-1; i++ ) {
    path = paths[i].split( /l|L/ );
    path[0] = path[0].replace( /m|M/, '' );
    for ( var j in path ) {
      path[j] = path[j].split( ',' );
      for ( var k in path[j] ) {
        path[j][k] = parseFloat( path[j][k] );
        if ( j != 0 ) {
          path[j][k] += path[j-1][k];
        }
      }
    }
    for ( var j in path ) {
      path[j] = path[j].join( ',' );
    }
    points[i] = path.join( ' ' );
  }
  return points;
}

Function get_term_parents() for WordPress

function get_term_parents( $id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
  $chain = '';
  $parent = &get_term( $id, $taxonomy );
  if ( is_wp_error( $parent ) )
    return $parent;
  if ( $nicename )
    $name = $parent->slug;
  else
    $name = $parent->name;
  if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
    $visited[] = $parent->parent;
    $chain .= get_term_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
  }
  if ( $link )
    $chain .= '<a href="' . esc_url( get_term_link( intval( $parent->term_id ), $taxonomy ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
  else
    $chain .= $name.$separator;
  return $chain;
}