Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Mike Boutin DWboutin

🎯
Focusing
  • Quebec city
View GitHub Profile
@DWboutin
DWboutin / itemstyle.xslt
Created Aug 27, 2015
Get image thumbnail in XSLT
View itemstyle.xslt
<xsl:variable name="URLimage">
<xsl:value-of select="substring-before(substring-after(@imageEvenement,'src=&#34;'),'&#34;')" />
</xsl:variable>
<xsl:variable name="ImgFilename">
<xsl:value-of select="substring-after($URLimage,'PublishingImages/')" />
</xsl:variable>
<xsl:variable name="URLThumb">
<xsl:value-of select="concat(substring-before($URLimage,$ImgFilename),'_t/',substring-before($ImgFilename,'.'),'_',substring-after($ImgFilename,'.'),'.',substring-after($ImgFilename,'.'))" />
</xsl:variable>
@DWboutin
DWboutin / itemstyle.xslt
Created Aug 28, 2015
Sharepoint 2010 format date french
View itemstyle.xslt
<!-- mercredi 5 août 2015 -->
<xsl:value-of select="ddwrt:FormatDate(@Date, 1036, 3)" />
@DWboutin
DWboutin / upload-thumnail.php
Last active Aug 29, 2015
Wordpress custom upload with thumbnail creation
View upload-thumnail.php
<?php
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
if(isset($_FILES['photo']['name']) && !empty($_FILES['photo']['name'])){
//Upload la photo dans le dossier
$uploadedfile = $_FILES['photo'];
$movefile = wp_handle_upload($uploadedfile, array('test_form' => false));
@DWboutin
DWboutin / functions.php
Created May 5, 2014
Wordpress custom the_exerpt length
View functions.php
<?php
function custom_excerpt_length( $length ) {
return 30;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
?>
View word_truncate.php
<?php
function truncate($str, $len){
$strArray = explode(' ', $str);
if(count($strArray) > $len){
$str = array_slice($strArray, 0, $len);
return implode(' ', $str) . '...';
}else{
return $str;
@DWboutin
DWboutin / functions.php
Created May 5, 2014
Wordpress post view count
View functions.php
<?php
// Compter le nombre de view
// Utiliser wpb_set_post_views($postID) dans toutes les pages à compter les views (single.php)
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
View dir_to_array.php
<?php
function dirToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value){
if (!in_array($value,array(".",".."))){
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)){
@DWboutin
DWboutin / functions.php
Created Jun 16, 2014
Add Registration field Woocommerce
View functions.php
<?php
//1. Add a new form element...
add_action('register_form','myplugin_register_form');
function myplugin_register_form (){
$first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
?>
<p>
<label for="first_name"><?php _e('First Name','mydomain') ?><br />
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
@DWboutin
DWboutin / functions.php
Created Jun 25, 2014
Woocommerce get product cat count
View functions.php
<?php
function wp_get_productcat_postcount($id) {
//return $count;
$args = array(
'post_type' => 'product', //post type, I used 'product'
'post_status' => 'publish', // just tried to find all published post
'posts_per_page' => -1, //show all
'tax_query' => array(
@DWboutin
DWboutin / functions.php
Created Jul 2, 2014
Custom taxonomy post count
View functions.php
<?php
function catCount($slug){
global $wpdb;
$query = "
SELECT COUNT( DISTINCT cat_posts.ID ) AS post_count
FROM gh_term_taxonomy AS cat_term_taxonomy INNER JOIN gh_terms AS cat_terms ON
cat_term_taxonomy.term_id = cat_terms.term_id
INNER JOIN gh_term_relationships AS cat_term_relationships