add google ads and analytics to lightbox

using this lightbox jquery plugin:
http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

$("a[rel^='prettyPhoto']").prettyPhoto({markup: '<div class="pp_pic_holder"> 
						<div class="ppt">&nbsp;</div> 
						<div class="pp_top"> 
							<div class="pp_left"></div> 
							<div class="pp_middle"></div> 
							<div class="pp_right"></div> 
						</div> 
						<div class="pp_content_container"> 
							<div class="pp_left"> 
							<div class="pp_right"> 
								<div class="pp_content"> 
									<div class="pp_loaderIcon"></div> 
									<div class="pp_fade"> 
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> 
											<a class="pp_next" href="#">next</a> 
											<a class="pp_previous" href="#">previous</a> 
										<div id="pp_full_res"></div> 
										<div class="pp_details"> 
											<div class="pp_nav"> 
												<a href="#" class="pp_arrow_previous">Previous</a> 
												<p class="currentTextHolder">0/0</p> 
												<a href="#" class="pp_arrow_next">Next</a> 
											</div> 
											<p class="pp_description"></p> 
                      <div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&href='+location.href+'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe></div> 
											<div class="pp_social"> 
<!-- BNL_Gallery_Bottom --> 
<div id="div-gpt-ad-1416042025558-3" style="width:728px; height:90px;"> 
<script type="text/javascript"> 
googletag.cmd.push(function() { googletag.display("div-gpt-ad-1416042025558-3"); }); 
</script> 
</div> 
</div> 
											<a class="pp_close" href="#">Close</a> 
										</div> 
									</div> 
								</div> 
							</div> 
							</div> 
						</div> 
						<div class="pp_bottom"> 
							<div class="pp_left"></div> 
							<div class="pp_middle"></div> 
							<div class="pp_right"></div> 
						</div> 
					</div> 
					<div class="pp_overlay"></div>',social_tools: '<div class="pp_social"></div><!-- BNL_Gallery_Bottom --><div id="div-gpt-ad-1416042025558-3" style="width:728px; height:90px;"><script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1416042025558-3"); });</script></div>',changepicturecallback: function(){
            googletag.cmd.push(function() { googletag.display("div-gpt-ad-1416042025558-3"); });
            _gaq.push(['_trackPageview', location.href]);
          }});
    
    
});

you will need to use asynchronous google analytics code like:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

example: http://www.purepixel.co.uk/2011/10/tracking-javascript-lightbox-and-ajax-page-views-with-google-analytics/

 

YUI link slideshows between multiple pages

this code is created by me to link galleries between pages on this squarespace site: http://irenehoffman.com/

using YUI library

 

  Y.use('node', function() {
      Y.on('domready', function() {
if (Y.one('.next-slide')) {
          if (!Modernizr.touch) {
              Y.one('body').on('mousemove', function(event) {
                  if (event.clientX <= Y.one('body').get('winWidth') / 2 && Y.one('.nav.subnav ul li.gallery-collection.active-link').previous()) {
                      Y.one('.arrow-wrapper.left').addClass('seko').siblings().removeClass('seko');
                  } else if (event.clientX > Y.one('body').get('winWidth') / 2 && Y.one('.nav.subnav ul li.gallery-collection.active-link').next()) {
                      Y.one('.arrow-wrapper.right').addClass('seko').siblings().removeClass('seko');
                  }
              });

              Y.one('body').on('mouseleave', function() {
                  Y.all('.arrow-wrapper').removeClass('seko');
              });

          }

          Y.one('.next-slide').on('click', function(event) {
              if (!Y.one('#fullscreenBrowser .slideshow > .sqs-active-slide').next() && Y.one('.nav.subnav ul li.gallery-collection.active-link').next()) {
                  window.location = Y.one('.nav.subnav ul li.gallery-collection.active-link').next().one('a').get('href');
              }
          });

          Y.one('.prev-slide').on('click', function(event) {
              if (!Y.one('#fullscreenBrowser .slideshow > .sqs-active-slide').previous() && Y.one('.nav.subnav ul li.gallery-collection.active-link').previous()) {
                  window.location = Y.one('.nav.subnav ul li.gallery-collection.active-link').previous().one('a').get('href');
              }
          });

      }


      });
  });

 

example of wordpress user query with meta key and value

$user_query = new WP_User_Query( array( 'meta_key' => 'round', 'meta_value' => get_the_author_meta('round', $queried_auther->ID) ) );
$args = array(
	'meta_query' => array(
		'relation' => 'AND',
		0 => array(
			'key'     => 'round',
			'value'   => get_the_author_meta('round', $queried_auther->ID),
			'compare' => '='
		),
		1 => array(
			'key'     => 'Time',
			'value'   => 0,
			'type'    => 'numeric',
			'compare' => '>'
		)
	),
	'meta_key' => 'Time',
    'orderby'   => 'meta_value_num',
	'order' => 'DESC',
	'fields' => 'ID'
 );

 

php get time difference by milliseconds

this is a function that calculates the difference between two times with milliseconds. i built it for a racing website to compare drivers.

function find_time_diff($t1, $t2, $ms=false) {
    $time1_pcs = explode(":", $t1);
	$time1_pcs2 = explode(".", $time1_pcs[2]);
	
    $time2_pcs = explode(":", $t2);
	$time2_pcs2 = explode(".", $time2_pcs[2]);
	
	$time1_all_ms = ($time1_pcs[0] * 60 * 60 * 1000) + ($time1_pcs[1] * 60 * 1000) + ($time1_pcs2[0] * 1000) + $time1_pcs2[1];
	$time2_all_ms = ($time2_pcs[0] * 60 * 60 * 1000) + ($time2_pcs[1] * 60 * 1000) + ($time2_pcs2[0] * 1000) + $time2_pcs2[1];
	$time1_all_ms_dif = $time2_all_ms - $time1_all_ms;
if($ms){
return $time1_all_ms_dif;
}
else{
	$dif_ms = $time1_all_ms_dif % 1000;
	$time1_all_ms_dif = floor($time1_all_ms_dif / 1000);

	$dif_s = $time1_all_ms_dif % 60;
	$time1_all_ms_dif = floor($time1_all_ms_dif / 60);

	$dif_m = $time1_all_ms_dif % 60;
	$time1_all_ms_dif = floor($time1_all_ms_dif / 60); 
	$dif_h = $time1_all_ms_dif % 60;

	return $dif_h.':'.$dif_m.':'.$dif_s.'.'.$dif_ms;
	}
}

 

WordPress Shortcode to get today’s birthday, yesterday and the day before

this is a shortcode created for a client to get the birthday of his employee from a custom database table with 3 varchar fields : name, area and date.

you will notice there is two versions one using server time and the other using wordpress current time function. because the timezone of the server is different than the user set timezone in wordpress

// [birthday-today] shortcode
function birthday_today_func( $atts ){

global $wpdb;

    $birthdays = $wpdb->get_results("SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(NOW()) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(NOW())");

    if($birthdays){
		
		$birthdays_out =  "Today's birthdays:<br><ul>";
		foreach ( $birthdays as $birthday ) 
		{
			$birthdays_out .= '<li> '.$birthday->name. ' - '.$birthday->area. ' - '.$birthday->date.'.</li>';
		}

		$birthdays_out .= '</ul>';

	}

if(date('D', $timestamp) === 'Mon') {

	$y_birthdays = $wpdb->get_results("SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST(NOW() - INTERVAL 1 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST(NOW() - INTERVAL 1 DAY AS DATE))");

	if($y_birthdays){
		$birthdays_out .= '<br>  Birthdays on '.date("l  d/m", strtotime("yesterday")).'<br><ul>';

		foreach ( $y_birthdays as $y_birthday ) 
		{
			$birthdays_out .= '<li> '.$y_birthday->name. ' - '.$y_birthday->area. ' - '.$y_birthday->date.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}




	$y2_birthdays = $wpdb->get_results("SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST(NOW() - INTERVAL 2 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST(NOW() - INTERVAL 2 DAY AS DATE))");

	if($y2_birthdays){
		$birthdays_out .= '<br>Birthdays on '.date("l d/m", strtotime("-2 day")).'<br><ul>';
		foreach ( $y2_birthdays as $y2_birthday ) 
		{
			$birthdays_out .= '<li> '.$y2_birthday->name. ' - '.$y2_birthday->area. ' - '.$y2_birthday->date.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}
}

return $birthdays_out;
}
add_shortcode( 'birthday-today', 'birthday_today_func' );
// [birthday-today] shortcode
function birthday_today_func( $atts ){

global $wpdb;
$current_time =current_time( 'mysql' );
$sql = "SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH('".$current_time."') AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY('".$current_time."')";
    $birthdays = $wpdb->get_results($sql);

    if($birthdays){
		//print_r($birthdays);
		$birthdays_out =  "Hoy cumplen años:<br><ul>";
		foreach ( $birthdays as $birthday ) 
		{
			//$birthdays_out .= '<li> '.$birthday->name. ' - '.$birthday->area. ' - ' .$birthday->date. '.</li>';
			$birthdays_out .= '<li> '.$birthday->name. ' - '.$birthday->area.'.</li>';
		}

		$birthdays_out .= '</ul>';

	}
	
	
if(current_time('D') === 'Mon') {
$sql2 = "SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST('".$current_time."' - INTERVAL 1 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST('".$current_time."' - INTERVAL 1 DAY AS DATE))";
	$y_birthdays = $wpdb->get_results($sql2);

	if($y_birthdays){
		$yest = $current_time.' -1 day';
		$birthdays_out .= '<br>  Cumplieron el domingo '.date("l  d/m", strtotime($yest)).'<br><ul>';

		foreach ( $y_birthdays as $y_birthday ) 
		{
			//$birthdays_out .= '<li> '.$y_birthday->name. ' - '.$y_birthday->area. ' - ' .$y_birthday->date.  '.</li>';
			$birthdays_out .= '<li> '.$y_birthday->name. ' - '.$y_birthday->area.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}



$sql3 = "SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST('".$current_time."' - INTERVAL 2 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST('".$current_time."' - INTERVAL 2 DAY AS DATE))";
	$y2_birthdays = $wpdb->get_results($sql3);

	if($y2_birthdays){
		$day_before_yest = $current_time.' -2 days';
		$birthdays_out .= '<br>Cumplieron el sabado '.date("l d/m", strtotime($day_before_yest)).'<br><ul>';
		foreach ( $y2_birthdays as $y2_birthday ) 
		{
			//$birthdays_out .= '<li> '.$y2_birthday->name. ' - '.$y2_birthday->area. ' - ' .$y2_birthday->date.  '.</li>';
			$birthdays_out .= '<li> '.$y2_birthday->name. ' - '.$y2_birthday->area.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}
}

return $birthdays_out;
}
add_shortcode( 'birthday-today', 'birthday_today_func' );

 

the result:

PSA Peugeot Citroën 2014-09-30 03-49-11

 

used with this plugin to import csv into the database table:
https://www.tipsandtricks-hq.com/wp-csv-to-database-plugin-import-excel-file-content-into-wordpress-database-2116