plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider' ), '1.6', true );
unset( $_SESSION['min_price'] );
unset( $_SESSION['max_price'] );
if ( isset( $_GET['min_price'] ) )
$_SESSION['min_price'] = $_GET['min_price'];
if ( isset( $_GET['max_price'] ) )
$_SESSION['max_price'] = $_GET['max_price'];
add_filter( 'loop_shop_post_in', 'woocommerce_price_filter' );
}
}
if (is_singular('product')) {
wp_enqueue_style('jqzoom', get_bloginfo('template_url') . '/scripts/jqzoom/jquery.jqzoom.css', true, 'all');
wp_enqueue_script('jqzoom', get_bloginfo('template_url') . '/scripts/jqzoom/jquery.jqzoom-core-pack.js', array('jquery'));
}
if (is_singular ())
wp_enqueue_script('comment-reply');
}
/* ===================
REGISTER MENUS
========================================================= */
if (function_exists('register_nav_menus')) {
register_nav_menus(
array(
'navigation_menu' => 'Navigation Menu',
'footer_menu' => 'Footer Menu'
)
);
}
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
}
/* ===================
JPG QUALITY & GLOBAL QUERY
========================================================= */
function jpeg_quality_callback($arg)
{
return (int)100;
}
add_filter('jpeg_quality', 'jpeg_quality_callback');
function is_post_type($type) {
global $wp_query;
if ($type == get_post_type($wp_query->post->ID))
return true;
return false;
}
/* ===================
HEADER CART (AJAX REFRESHING)
========================================================= */
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - cart->get_cart_total(); ?>
[' => '[',
']
' => ']',
'] ' => ']'
);
$content = strtr($content, $array);
return $content;
}
/* ============
WOOCOMMERCE - How many columns on one loop page
========================================================= */
function loop_columns() {
global $data;
if ($data['loopcolno']) {
return $data['loopcolno'];
} else {
return 2;
}
}
add_filter('loop_shop_columns', 'loop_columns');
/* ============
WOOCOMMERCE - How many products&columns - related products
========================================================= */
function woocommerce_output_related_products() {
woocommerce_related_products(4, 4); // 3 products, 3 columns
}
/* ============
WOOCOMMERCE - How many products on one loop page
========================================================= */
function loop_shop_per_page() {
global $data;
if ($data['loopno']) {
return $data['loopno'];
} else {
return 6;
}
}
add_filter('loop_shop_per_page', 'loop_shop_per_page');
/* ============
WOOCOMMERCE - Deregister css
========================================================= */
define('WOOCOMMERCE_USE_CSS', false);
/* ============
BREADCRUMBS
========================================================= */
remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
add_action('woocommerce_before_main_content', 'dimox_breadcrumbs', 20, 0);
function dimox_breadcrumbs($delimiter = ' › ', $wrap_before = '', $wrap_after = '
', $before = '', $after = '', $home = null) {
global $post, $wp_query, $author, $paged;
if (!$home)
$home = _x('Home', 'breadcrumb', 'woothemes');
$home_link = home_url();
$prepend = '';
if (get_option('woocommerce_prepend_shop_page_to_urls') == "yes" && get_option('woocommerce_shop_page_id') && get_option('page_on_front') !== get_option('woocommerce_shop_page_id'))
$prepend = $before . '' . get_the_title(get_option('woocommerce_shop_page_id')) . ' ' . $after . $delimiter;
if ((!is_home() && !is_front_page() && !(is_post_type_archive() && get_option('page_on_front') == get_option('woocommerce_shop_page_id'))) || is_paged()) :
echo $wrap_before;
echo $before . '' . $home . ' ' . $after . $delimiter;
if (is_category ()) :
$cat_obj = $wp_query->get_queried_object();
$this_category = $cat_obj->term_id;
$this_category = get_category($this_category);
if ($thisCat->parent != 0) :
$parent_category = get_category($this_category->parent);
echo get_category_parents($parent_category, TRUE, $delimiter);
endif;
echo $before . single_cat_title('', false) . $after;
elseif (is_tax('product_cat')) :
//echo $before . '' . ucwords(get_option('woocommerce_shop_slug')) . ' ' . $after . $delimiter;
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
$parents = array();
$parent = $term->parent;
while ($parent):
$parents[] = $parent;
$new_parent = get_term_by('id', $parent, get_query_var('taxonomy'));
$parent = $new_parent->parent;
endwhile;
if (!empty($parents)):
$parents = array_reverse($parents);
foreach ($parents as $parent):
$item = get_term_by('id', $parent, get_query_var('taxonomy'));
echo $before . '' . $item->name . ' ' . $after . $delimiter;
endforeach;
endif;
$queried_object = $wp_query->get_queried_object();
echo $prepend . $before . $queried_object->name . $after;
elseif (is_tax('product_tag')) :
$queried_object = $wp_query->get_queried_object();
echo $prepend . $before . __('Products tagged “', 'woothemes') . $queried_object->name . '”' . $after;
elseif (is_day ()) :
echo $before . '' . get_the_time('Y') . ' ' . $after . $delimiter;
echo $before . '' . get_the_time('F') . ' ' . $after . $delimiter;
echo $before . get_the_time('d') . $after;
elseif (is_month ()) :
echo $before . '' . get_the_time('Y') . ' ' . $after . $delimiter;
echo $before . get_the_time('F') . $after;
elseif (is_year ()) :
echo $before . get_the_time('Y') . $after;
elseif (is_post_type_archive('product') && get_option('page_on_front') !== get_option('woocommerce_shop_page_id')) :
$_name = get_option('woocommerce_shop_page_id') ? get_the_title(get_option('woocommerce_shop_page_id')) : ucwords(get_option('woocommerce_shop_slug'));
if (is_search ()) :
echo $before . '' . $_name . ' ' . $delimiter . __('Search results for “', 'woothemes') . get_search_query() . '”' . $after;
else :
echo $before . '' . $_name . ' ' . $after;
endif;
elseif (is_single() && !is_attachment()) :
if (get_post_type() == 'product') :
//echo $before . '' . ucwords(get_option('woocommerce_shop_slug')) . ' ' . $after . $delimiter;
echo $prepend;
if ($terms = wp_get_object_terms($post->ID, 'product_cat')) :
$term = current($terms);
$parents = array();
$parent = $term->parent;
while ($parent):
$parents[] = $parent;
$new_parent = get_term_by('id', $parent, 'product_cat');
$parent = $new_parent->parent;
endwhile;
if (!empty($parents)):
$parents = array_reverse($parents);
foreach ($parents as $parent):
$item = get_term_by('id', $parent, 'product_cat');
echo $before . '' . $item->name . ' ' . $after . $delimiter;
endforeach;
endif;
echo $before . '' . $term->name . ' ' . $after . $delimiter;
endif;
echo $before . get_the_title() . $after;
elseif (get_post_type() != 'post') :
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo $before . '' . $post_type->labels->singular_name . ' ' . $after . $delimiter;
echo $before . get_the_title() . $after;
else :
$cat = current(get_the_category());
echo get_category_parents($cat, TRUE, $delimiter);
echo $before . get_the_title() . $after;
endif;
elseif (is_404 ()) :
echo $before . __('Error 404', 'woothemes') . $after;
elseif (!is_single() && !is_page() && get_post_type() != 'post') :
$post_type = get_post_type_object(get_post_type());
if ($post_type) : echo $before . $post_type->labels->singular_name . $after;
endif;
elseif (is_attachment ()) :
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
echo get_category_parents($cat, TRUE, '' . $delimiter);
echo $before . '' . $parent->post_title . ' ' . $after . $delimiter;
echo $before . get_the_title() . $after;
elseif (is_page() && !$post->post_parent) :
echo $before . get_the_title() . $after;
elseif (is_page() && $post->post_parent) :
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . ' ';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) :
echo $crumb . '' . $delimiter;
endforeach;
echo $before . get_the_title() . $after;
elseif (is_search ()) :
echo $before . __('Search results for “', 'woothemes') . get_search_query() . '”' . $after;
elseif (is_tag ()) :
echo $before . __('Posts tagged “', 'woothemes') . single_tag_title('', false) . '”' . $after;
elseif (is_author ()) :
$userdata = get_userdata($author);
echo $before . __('Author:', 'woothemes') . ' ' . $userdata->display_name . $after;
endif;
if (get_query_var('paged')) :
echo ' (' . __('Page', 'woothemes') . ' ' . get_query_var('paged') . ')';
endif;
echo $wrap_after;
endif;
}
/* =================
PAGINATION (thanks to woocommerce ;>)
========================================================= */
function woocommerce_pagination($pages = '', $range = 2) {
$showitems = ($range * 2) + 1;
global $paged;
if (empty($paged))
$paged = 1;
if ($pages == '') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if (!$pages) {
$pages = 1;
}
}
if (1 != $pages) {
echo "\n";
}
}
/* =================
PRICE FILTER SLIDER INIT
========================================================= */
global $woocommerce;
if (isset($woocommerce)) {
add_action('init', 'woocommerce_price_filter_init');
add_filter('loop_shop_post_in', 'woocommerce_price_filter');
}
/* =================
ENABLE PAGINATION FOR TAXONOMIES
========================================================= */
$option_posts_per_page = get_option( 'posts_per_page' );
add_action( 'init', 'my_modify_posts_per_page', 0);
function my_modify_posts_per_page() {
add_filter( 'option_posts_per_page', 'my_option_posts_per_page' );
}
function my_option_posts_per_page( $value ) {
global $option_posts_per_page;
global $data;
if (is_tax('services_rendered') || is_post_type_archive('portfolio')) {
return $data['folio_itemsno'];
} else {
return $option_posts_per_page;
}
}
/* =================
LIMIT WORDS IN CONTENT PREVIEW
========================================================= */
function content($limit) {
$content = explode(' ', get_the_content('', false), $limit);
if (count($content) >= $limit) {
array_pop($content);
$content = implode(" ", $content) . '...';
} else {
$content = implode(" ", $content);
}
$content = preg_replace('/\[.+\]/', '', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
/* ===================
OPTIONS
========================================================= */
add_filter('the_content', 'do_shortcode');
if (!isset($content_width))
$content_width = 1000;
if (!function_exists('woocommerce_template_single_excerpt')) {
function woocommerce_template_single_excerpt( $post ) {
global $post;
if ($post->post_excerpt) echo '' . do_shortcode(wpautop(wptexturize($post->post_excerpt))) . '
';
}
}
/* =================
CUSTOM MORE LINK
========================================================= */
function the_more() {
global $post;
if (strpos($post->post_content, '')):
$the_more = '';
$the_more .= 'Read more ';
$the_more .= ' ';
echo $the_more;
endif;
}
/* ==============================
CUSTOM GALLERY
=========================================================== */
function my_gallery($content) {
//remove space between [ and gallery in the following line
return str_replace('[gallery', '[gallery itemtag="div" icontag="span" captiontag="p" size="booklet"', $content);
}
add_filter('the_content', 'my_gallery');
add_filter('gallery_style', 'my_gallery_style', 99);
function my_gallery_style() {
return "";
}
function remove_revisions_metabox() {
remove_meta_box('revisionsdiv', 'post', 'normal');
remove_meta_box('revisionsdiv', 'page', 'normal');
}
add_action('admin_menu', 'remove_revisions_metabox');
/* ==============================
CUSTOM POST TYPE - PORTFOLIO
=========================================================== */
add_action('init', 'create_portfolio');
function create_portfolio() {
$portfolio_args = array(
'label' => __('Portfolio'),
'singular_label' => __('Portfolio'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'has_archive' => true,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt')
);
register_post_type('portfolio', $portfolio_args);
}
add_action("admin_init", "add_portfolio");
function add_portfolio() {
add_meta_box("portfolio_details", "portfolio_options", "portfolio", "normal", "low");
}
add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
add_action("manage_posts_custom_column", "portfolio_columns_display");
add_action('init', 'services_rendered', 0);
function services_rendered() {
register_taxonomy(
'services_rendered',
'portfolio',
array(
'hierarchical' => true,
'label' => 'Provided services',
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' )
)
);
}
function portfolio_edit_columns($portfolio_columns) {
$portfolio_columns = array(
"cb" => "
",
"title" => "Project Title",
"description" => "Description",
"services" => "services",
);
return $portfolio_columns;
}
function portfolio_columns_display($portfolio_columns) {
switch ($portfolio_columns) {
case "description":
the_excerpt();
break;
case "services":
global $post;
echo get_the_term_list($post->ID, 'services_rendered', '
');
break;
}
}
add_action( 'admin_head', 'my_portfolio_icons' );
function my_portfolio_icons() {
?>