/** * Generate column classes */ function builder_column_class(&$prev_width, $col, $extra_class = '') { global $spyropress_builder; $classes = array(); // grid col size class $classes[] = 'span' . str_replace('/', 'by', $col->config['size']); if ('skt' == get_html_framework()) { $classes[] = get_skeleton_class($col->config['size']); } if ('fd3' == get_html_framework()) { $classes[] = get_foundation3_class($col->config['size']); } if ('bs3' == get_html_framework()) { $classes[] = 'col-md-' . $col->config['size']; } // add span_first class $width = is_string($col->config['size']) ? (int) 1 / 3 * 16 : (int) $col->config['size']; $new_width = $prev_width + $width; if ($prev_width == 0) { $classes[] = get_first_column_class(); $prev_width = $new_width; } elseif (get_grid_columns() - $new_width < 0) { $prev_width = $width; $classes[] = get_first_column_class(); } else { $prev_width = $new_width; } if (get_grid_columns() == $new_width) { $prev_width = 0; $classes[] = get_last_column_class(); } // extra class define by row block if ($extra_class != '') { $classes[] = $extra_class; } return spyropress_clean_cssclass($classes); }
/** * Query Generator * Generate query and loop through it, with column logic enabled. */ function spyropress_query_generator($atts, $content = null) { // default setting $default = array('callback' => '', 'row' => 1, 'row_container' => 'div', 'row_class' => get_row_class(true), 'column_class' => '', 'columns' => 1, 'pagination' => false); $atts = wp_parse_args($atts, $default); $output = ''; $counter = $column_counter = 0; $columns = $atts['columns']; $callback = $atts['callback']; $close = false; // Add Pagination if ($atts['limit']) { $atts['posts_per_page'] = $atts['limit']; unset($atts['limit']); if ($atts['pagination']) { $atts['paged'] = get_page_query(); } } // set column cssClass $colclass = array(); $colclass[] = get_column_class($columns); $colclass[] = $atts['column_class']; // if is archive merge wp_query if (is_archive() || is_search()) { global $wp_query; if (!empty($wp_query->query)) { $atts = array_merge($wp_query->query, $atts); } } // init wp_query $posts = new WP_Query($atts); if ($posts->have_posts()) { while ($posts->have_posts()) { $posts->the_post(); $counter++; // if has column defined if ($columns) { $column_counter++; $colclass_fl = array(); if ($column_counter == 1) { if ($atts['row']) { $output .= '<' . $atts['row_container'] . ' class="' . $atts['row_class'] . '">'; $close = true; } $colclass_fl[] = get_first_column_class(); } if ($column_counter == $columns) { $colclass_fl[] = get_last_column_class(); } $atts['column_class'] = spyropress_clean_cssclass(array_merge($colclass, $colclass_fl)); // get the item using the defined callback function if ($callback) { $output .= call_user_func_array($callback, array(get_the_ID(), $atts, $counter, $column_counter)); } if ($column_counter == $columns) { $column_counter = 0; if ($atts['row']) { $output .= '</' . $atts['row_container'] . '>'; $close = false; } } } else { if ($callback) { $output .= call_user_func_array($callback, array(get_the_ID(), $atts, $counter, $column_counter)); } } } // close last unclosed row if (isset($atts['row']) && $atts['row'] && $close) { $output .= '</' . $atts['row_container'] . '>'; } wp_reset_query(); // get pagination for query if enabled $pagination = ''; if ($atts['pagination']) { $pagination = wp_pagenavi(array('query' => $posts, 'echo' => false)); } return array('content' => $output, 'pagination' => $pagination); } else { wp_reset_query(); return; } }