WPML and Event Manager Plugin Compatibility

Posted By aronblack / July, 12, 2012 / 0 comments

Add this code snippet to your functions.php or download it from http://pastebin.com/a1fc7vsE

function em_wpml_integration($conditions, $args){
global $wpdb;
if( defined('ICL_LANGUAGE_CODE') ){
$conditions['wpml'] = EM_EVENTS_TABLE.'.post_id IN (SELECT element_id FROM '.$wpdb->prefix."icl_translations WHERE language_code ='".ICL_LANGUAGE_CODE."' AND element_type='post_".EM_POST_TYPE_EVENT."')";
}
return $conditions;
}
add_filter('em_events_build_sql_conditions','em_wpml_integration',10,2);
function em_wpml_integration_locations($conditions, $args){
global $wpdb;
if( defined(‘ICL_LANGUAGE_CODE’) ){
$conditions[‘wpml’] = EM_LOCATIONS_TABLE.’.post_id IN (SELECT element_id FROM ‘.$wpdb->prefix.”icl_translations WHERE language_code ='”.ICL_LANGUAGE_CODE.”‘ AND element_type=’post_”.EM_POST_TYPE_LOCATION.”‘)”;
}
return $conditions;
}
add_filter(’em_locations_build_sql_conditions’,’em_wpml_integration_locations’,10,2);function em_wmpl_location_save($result, $EM_Location){
global $wpdb;
if( !$wpdb->get_var("SELECT translation_id FROM {$wpdb->prefix}icl_translations WHERE element_id=$EM_Location->post_id") ){
//save a value into WPML table
$wpdb->insert($wpdb->prefix.'icl_translations', array('element_type'=>"post_".EM_POST_TYPE_LOCATION, 'trid'=>$EM_Location->post_id, 'element_id'=>$EM_Location->post_id, 'language_code'=>ICL_LANGUAGE_CODE));
}
return $result;
}
add_filter('em_location_save','em_wmpl_location_save',10,2);

Cycle plugin & Fancybox conflict

Posted By aronblack / February, 11, 2012 / 0 comments

On my latest project, I was trying to integrate Fancybox plugin and jQuery Cycle plugin on the same page. They didn’t play nicely together at first but eventually I got them to work.

The best approach was to use jQuery.noConflict();

First off, I call the FancyBox js files before the Cycle plugin and I reassigned the FancyBox JQuery shortcut to use $jq instead of the standard $.

Here’s the code for how I did it:

<!-- FANCY BOX -->
<link rel="stylesheet" href="/scripts/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
 var $jq = jQuery.noConflict();
</script>
<script type="text/javascript" src="/scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<!-- JQUERY CYCLE -- >
<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">
   jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
 $("#s4")
.after('<div id="slide-show-nav">')
.cycle({
    fx:     'fade',
    speed:  800,
    timeout: 4300,
	pause: 1,
    pager:  '#slide-show-nav',
	 pagerAnchorBuilder: function(idx, slide) {
        return '<a href="#" style="width: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;</a>';
    } 

});

  });

</script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$jq("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

 });

</script>