Hello I'm working on a wordpress site and I currently have a popup set to display if an arrtibute in the shortcode is set to "popup="register")... I added another lightbox that I want to display if the attribute is set to "popup="apply")
My question is how to add another variable to the following function.. would I need an if statement? Im new to php, any advice is greatly appreciated.. Thanks!!!!
function oxy_shortcode_button_fancy($atts , $content = '' ) {
// setup options
extract( shortcode_atts( array(
'button_swatch' => 'swatch-coral',
'button_animation' => '',
'size' => 'default',
'xclass' => '',
'link' => '',
'label' => 'My button',
'icon' => '',
'link_open' => '_self',
'popup' => ''
), $atts ) );
$popup = ('register' == $popup) ? ' onclick="jQuery(\'#registerid, .overlayLogin\').show();"' : '';
$animation = ( $button_animation != "") ? ' data-animation="'.$button_animation.'"' :"";
return '<a'.$popup.' href="'. $link .'" class="btn '. $size.' btn-icon-right '. $xclass . ' '. $button_swatch .'" target="' . $link_open . '"> '. $label . '<span><i class="'.$icon.'" '.$animation.'></i></span></a>';
}
What i'm looking to add is:
$popup = ('apply' == $popup) ? ' onclick="jQuery(\'#applyid, .overlayLogin\').show();"' : '';
Try using this codes..Hope it helps you
function oxy_shortcode_button_fancy($atts , $content = '' ) {
// setup options
extract( shortcode_atts( array(
'button_swatch' => 'swatch-coral',
'button_animation' => '',
'size' => 'default',
'xclass' => '',
'link' => '',
'label' => 'My button',
'icon' => '',
'link_open' => '_self',
'popup' => ''
), $atts ) );
if('register' == $popup) {
$popup = ('register' == $popup) ? ' onclick="jQuery(\'#registerid, .overlayLogin\').show();"' : '';
} else {
$popup = ('apply' == $popup) ? ' onclick="jQuery(\'#applyid, .overlayLogin\').show();"' : '';
}
$animation = ( $button_animation != "") ? ' data-animation="'.$button_animation.'"' :"";
return '<a'.$popup.' href="'. $link .'" class="btn '. $size.' btn-icon-right '. $xclass . ' '. $button_swatch .'" target="' . $link_open . '"> '. $label . '<span><i class="'.$icon.'" '.$animation.'></i></span></a>';
}
Related
add_filter( 'woocommerce_form_field_args', 'custom_form_field_args', 10, 3 );
function custom_form_field_args( $args, $key, $value ) {
if ( $args['id'] == 'billing_city' ) {
$args = array(
'label' => __( 'Town / City', 'woocommerce' ),
'required' => TRUE,
'clear' => TRUE,
'type' => 'select',
'options' => array(
'' => ('Select City' ),
'Duliajan' => ('Duliajan' )
),
'class' => array( 'update_totals_on_change' )
);
} // elseif … and go on
return $args;
};
When I add the piece of code for a single city in (woocommerce) function.php, I got the following error.
Line number 2040-- $field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ) . '">
Line no 2064-- $field_html .= '<label for="' . esc_attr( $label_id ) . '" class="' . esc_attr( implode( ' ', $args['label_class'] ) ) . '">' . $args['label'] . $required . '</label>';
How can I solve the error?
$args['input_class'] and $args['label_class'] must be arrays so they are probably not. Your should check:
if (!is_array($args['label_class']) {
// initialize to some empty array? depends on your application, what it needs to do
}
Hi I am working with a Wordpress gallery plugin.
I would like the first link in the filter menu to automatically be active when the page loads. This is as by default it loads ALL the images from all the categories and it's too many! Thanks.
<?php
wp_enqueue_script('imagesloaded', plugins_url('/assets/plugins/imagesloaded/imagesloaded.pkgd.min.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
wp_enqueue_script('isotope', plugins_url('/assets/plugins/isotope/isotope.pkgd.min.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
wp_enqueue_script('go-gallery', plugins_url('/assets/js/gallery.js', __FILE__), array('jquery', 'isotope', 'imagesloaded'), GO_GALLERY_VERSION, true);
wp_enqueue_style('go-gallery', plugins_url('/assets/css/gallery.css', __FILE__), null, GO_GALLERY_VERSION);
wp_enqueue_script('tos', plugins_url('/assets/plugins/tos/js/jquery.tosrus.min.custom.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
wp_enqueue_style('tos', plugins_url('/assets/plugins/tos/css/jquery.tosrus.custom.css', __FILE__), null, GO_GALLERY_VERSION);
$labels = array(
'name' => _x('Media Categories', 'taxonomy general name', 'go_gallery'),
'singular_name' => _x('Media Category', 'taxonomy singular name', 'go_gallery'),
'search_items' => __('Search Media Categories', 'go_gallery'),
'all_items' => __('All Media Categories', 'go_gallery'),
'parent_item' => __('Parent Media Category', 'go_gallery'),
'parent_item_colon' => __('Parent Media Category:', 'go_gallery'),
'edit_item' => __('Edit Media Category', 'go_gallery'),
'update_item' => __('Update Media Category', 'go_gallery'),
'add_new_item' => __('Add New Media Category', 'go_gallery'),
'new_item_name' => __('New Media Category Name', 'go_gallery'),
'menu_name' => __('Media Categories', 'go_gallery'),
);
$args = array(
'hierarchical' => TRUE,
'labels' => $labels,
'show_ui' => TRUE,
'show_admin_column' => TRUE,
'query_var' => TRUE,
'rewrite' => TRUE,
);
register_taxonomy('attachment_category', 'attachment', $args );
$output = '';
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => $atts['limit'],
'order' => 'DESC',
'orderby' => $atts['sort'],
'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png'
);
$categories = array();
$atts['icat'] = array_map('sanitize_title', explode(',', $atts['icat']));
foreach ( $atts['icat'] as $category ) {
if ( $term = get_term_by('slug', $category, 'attachment_category') ) {
$categories[$term->term_id] = $term;
}
}
if ( !empty($categories) ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'attachment_category',
'field' => 'term_id',
'terms' => array_keys($categories)
)
);
}
$atts['menu_gap'] = min($atts['menu_gap'], 100);
$classes[] = 'go-gallery';
$classes[] = 'menu-' . $atts['menu_pos'];
$classes[] = go_gallery_bool($atts['menu_show']) ? 'menu-show' : '';
$classes[] = 'size-' . $atts['size'];
$classes[] = 'style-' . $atts['style'];
$attributes = array();
$attributes['class'] = join(' ', $classes);
$attributes['id'] = 'go-' . substr(md5(mt_rand(0, PHP_INT_MAX)), 0, 6);
$attributes['data-gap'] = intval($atts['gap']);
$attributes['data-border-color'] = $atts['border_color'];
$attributes['data-lightbox'] = go_gallery_bool($atts['lightbox']) ? 'yes' : 'no';
$attributes['data-desc-color'] = $atts['desc_color'];
$attributes['data-menu-color'] = $atts['menu_color'];
$attributes['data-menu-bg'] = $atts['menu_bg'];
$attributes['data-menu-bg-hover'] = $atts['menu_bg_hover'];
$attributes['data-menu-gap'] = $atts['menu_gap'];
$attributes['data-bg'] = $atts['bg'];
$attributes['data-border-size'] = $atts['border_size'];
$attributes['data-overlay-color'] = go_gallery_hex2rgb($atts['overlay_color']);
$thumb_size = 'medium';
if ( $atts['size'] == 'large' || ($atts['style'] == 'squared' && in_array($atts['size'], array('medium', 'large'))) ) {
$thumb_size = 'large';
}
foreach ( $attributes as $attribute => $value ) {
$attributes[$attribute] = $attribute . '="' . $value . '"';
}
$query = new WP_Query($args);
$output .= '<div ' . join(' ', $attributes) . '>';
$output .= '<ul class="go-gallery-filters">';
$output .= '<li>';
$output .= '<a data-filter="" href="#">' . __($atts['menu_button'], 'go_gallery') . '</a>';
$output .= '</li>';
foreach ( $categories as $category ) {
if ( !empty($category) ) {
$output .= '<li class="active">';
$output .= '<a data-filter="' . $category->slug . '" href="#">' . $category->name . '</a>';
$output .= '</li>';
}
}
$output .= '</ul>';
$output .= '<div class="go-gallery-list-wrapper">';
$output .= '<ul class="go-gallery-list">';
foreach ( $query->posts as $post ) {
$category_terms = wp_get_post_terms($post->ID, 'attachment_category');
$classes = array();
$classes[] = 'go-gallery-item';
foreach ( $category_terms as $category_term ) {
$classes[] = 'category-' . $category_term->slug;
}
$image_source = wp_get_attachment_image_src($post->ID, 'full');
$output .= '<li data-source="' . $image_source[0] . '" class="' . join(' ', $classes) . '">';
$output .= '<a class="image-wrap" href="' . $image_source[0] . '">';
$output .= '<figure>';
$output .= wp_get_attachment_image($post->ID, $thumb_size);
$output .= '<div class="image-overlay">';
if ( go_gallery_bool( $atts['hover_data'] ) ){
$output .= '<h3>' . $post->post_title . '</h3>';
$output .= '<h4>' . $post->post_content . '</h4>';
}
$output .= '</div>';
$output .= '</figure>';
$output .= '</a>';
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</div>';
$output .= '</div>';
return $output;
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = array($r, $g, $b);
return 'rgba(' . join(', ', $rgb) . ', ' . $alpha .')';
That depends what you mean with "active".
:active is a CSS pseudo selector that can change the appearance of a link while it is being activated. If you want to add a css-class "active" to the first li-element in your loop, you could try something like the following:
foreach($categories as $category) {
$counter = 0; // COUNTER OF CATEGORIES...
$selected = ''; // THE STRING TO PRINT IN SELECTED LI-ELEMENT
if ( !empty($category) ) {
$selected = ($counter == 0) ? 'class="active"' : ''; // SET CLASS ACTIVE FOR THE FIRST CATEGORY
$output .= '<li '. $selected .'>';
$output .= '<a data-filter="' . $category->slug . '" href="#">' . $category->name . '</a>';
$output .= '</li>';
$counter++; //INCREMENT COUNTER OF CATEGORIES
}
}
Assuming your categories get sent via a simple link like so:
first category
second category
then you would have something like this in php:
if(isset($_GET['category']) {
$category_id = $_GET['category'];
} else {
$category_id = 1; // default
}
// this is a blank guess, we don't know where you get your data from:
$category = $categories[$category_id];
The rest depends on your data-structure.
But this is how you could set a default category.
I am trying to add the list box on the single product page, I was wondering no option for multiselect in woocommerce, For get_option fields woocommerce supporting multiselect but for post_meta woocommerce support only single select, Not sure is there any limitation in woocommerce or i could miss something to get multiselect? Here is the below code i tried
function create_multiselect() {
woocommerce_wp_select(array(
'id' => 'newoptions',
'class' => 'newoptions',
'label' => __('Testing Multiple Select', 'woocommerce'),
'options' => array(
'1' => 'User1',
'2' => 'User2',
'3' => 'User3',
))
);
}
add_action("woocommerce_product_options_pricing","create_multiselect");
Any Suggestion would be great.
It is not necessary to create a new function. The woocommerce_wp_select handles this out of the box. One of the attributes available is the custom_attributes which can accept an array. If you pass in an array('multiple'=>'multiple) then it renders a multiselect. In order to serialize and handle the input, you just provide a name[] in the name field and it works like magic. Here is an example -
woocommerce_wp_select(
array(
'id' => '_cb_days_available',
'name' => '_cb_days_available[]',
'label' => __('Days Offered', 'woocommerce'),
'description' => 'Which days of the week is this charter available?',
'default' => get_option('cb_open_days'),
'desc_tip' => 'true',
'class' => 'cb-admin-multiselect',
'options' => array(
'Mon' => 'Monday',
'Tue' => 'Tuesday',
'Wed' => 'Wednesday',
'Thu' => 'Thursday',
'Fri' => 'Friday',
'Sat' => 'Saturday',
'Sun' => 'Sunday'
),
'custom_attributes' => array('multiple' => 'multiple')
)
);
woocommerce_wp_select() function does not support multiselect, you can open the wc-meta-box-functions.php file in /woocommerce/includes/admin directory to see the default behavior.
But what's stopping you to create your own function that will be based on the default Woo function, and add the required features, or even change the default function ( but still, modifying the plugin files is not the best practice ). Here's an example of how to write a new function with multiple support, the only changes from original are added support for name and multiple attributes, and different logic for the selected items ( since post meta is now an array ).
function woocommerce_wp_select_multiple( $field ) {
global $thepostid, $post, $woocommerce;
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['value'] = isset( $field['value'] ) ? $field['value'] : ( get_post_meta( $thepostid, $field['id'], true ) ? get_post_meta( $thepostid, $field['id'], true ) : array() );
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" multiple="multiple">';
foreach ( $field['options'] as $key => $value ) {
echo '<option value="' . esc_attr( $key ) . '" ' . ( in_array( $key, $field['value'] ) ? 'selected="selected"' : '' ) . '>' . esc_html( $value ) . '</option>';
}
echo '</select> ';
if ( ! empty( $field['description'] ) ) {
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
} else {
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
}
}
echo '</p>';
}
Example of how to use the function:
woocommerce_wp_select_multiple( array(
'id' => 'newoptions',
'name' => 'newoptions[]',
'class' => 'newoptions',
'label' => __('Testing Multiple Select', 'woocommerce'),
'options' => array(
'1' => 'User1',
'2' => 'User2',
'3' => 'User3',
))
);
Here's a shortcode of mine:
function sc_link( $atts ) {
extract( shortcode_atts(
array(
'page' => '',
'style' => 'button',
'window' => 'self',
'label' => 'Missing Label Tag: label=""',
), $atts )
);
return '' . $label . '';
}
add_shortcode( 'mylink', 'sc_link' );
What I want to be able to do is a conditional before the return: if $window = 'new' then echo 'blank'.
Think this is what your trying to do what id suggest doing is leaving window blank and just doing an if statement on that
How you want it
function sc_link( $atts ) {
extract( shortcode_atts(
array(
'page' => '',
'style' => 'button',
'window' => 'self',
'label' => 'Missing Label Tag: label=""',
), $atts )
);
if($window == "new"){
$link = '' . $label . '';
}else{
$link = '' . $label . '';
}
return $link;
}
add_shortcode( 'mylink', 'sc_link' );
How it should be
function sc_link( $atts ) {
extract( shortcode_atts(
array(
'page' => '',
'style' => 'button',
'window' => '',
'label' => 'Missing Label Tag: label=""',
), $atts )
);
if(!$window){
$link = '' . $label . '';
}else{
$link = '' . $label . '';
}
return $link;
}
add_shortcode( 'mylink', 'sc_link' );
The your shortcode will be link
[shorcode page="" window="" label=""]
Here is an easy short code conditional output example. I would recommend being sparing with this type of syntax because it can get lost in the fray.
echo ($window === 'new') ? $window : '';
This format is conditional ? what to do if true : what to do if false
Existing array code:
function get_menu($menu = array(), $ulclass = '', $is_main_menu = false) {
global $menu_selected;
$output = '';
if (empty($menu)) {
return $output;
}
$output .= '<ul' . (!empty($ulclass) ? (' class="' . $ulclass . '"') : '') . '>';
foreach($menu as $item) {
if (!$is_main_menu || !isset($item['hide_in_main']) || !$item['hide_in_main']) {
$li_class = (isset($item['sub']) && !empty($item['href']) ? ('dir') : '');
if (isset($menu_selected) && !empty($menu_selected) && $menu_selected == $item['href']) {
$li_class = (!empty($li_class)) ? $li_class . ' selected' : 'selected';
}
if (isset($item['li_class']) && !empty($item['li_class'])) {
$li_class .= (!empty($li_class)) ? ' ' . $item['li_class'] : $item['li_class'];
}
$output .= '<li' . (!empty($li_class) ? ' class="' . $li_class . '"': '' ) . '>';
$output .= '<a';
if (isset($item['href']) && !empty($item['href'])) {
$output .= ' href="' . $item['href'] .'"';
}
if (isset($item['title']) && !empty($item['title'])) {
$output .= ' title="' . $item['title'] .'"';
}
if (isset($item['class']) && !empty($item['class'])) {
$output .= ' class="' . $item['class'] .'"';
}
if (isset($item['target']) && !empty($item['target'])) {
$output .= ' target="' . $item['target'] .'"';
}
$output .= '>';
if (isset($item['title']) && !empty($item['title'])) {
$output .= $item['title'];
} else if (isset($item['href']) && !empty($item['href'])) {
$output .= $item['href'];
}
$output .= '</a>';
if (isset($item['sub']) && !empty($item['sub'])) {
$output .= get_menu($item['sub'], $ulclass);
}
$output .= '</li>';
}
}
$output .= '</ul>';
return $output;
}
Existing Array:
$menu[] = array(
'title' => 'Home',
'href' => 'index.php'
);
$menu[] = array(
'title' => 'Summer Activites',
'href' => 'activities.php'
);
$menu[] = array(
'title' => 'Winter Activities',
'href' => 'wactivities.php'
);
$menu[] = array(
'title' => 'Image Gallery',
'href' => 'gallery.php'
);
I want to add submenus
ie: summer activities and winter activities would be child menu items under a parent Activities
Any help would be so appreciated
Thanks in advance.
Have you actually tried doing this or are you being lazy?
Practice makes perfect!
$menu[] = array(
'title' => 'Activities',
'sub' => array(
array(
'title' => 'Summer Activites',
'href' => 'activities.php' ),
array(
'title' => 'Winter Activities',
'href' => 'wactivities.php')
)
)
);
Looks like it should work.